|
@@ -0,0 +1,102 @@
|
|
|
|
+<?php
|
|
|
|
+/**
|
|
|
|
+ * Created by PhpStorm.
|
|
|
|
+ * User: Noa
|
|
|
|
+ * Date: 27/03/2016
|
|
|
|
+ * Time: 17:02
|
|
|
|
+ */
|
|
|
|
+require_once __DIR__."/../config.php";
|
|
|
|
+
|
|
|
|
+// generate map autoloader map file
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Walk on dir to found files
|
|
|
|
+ * @param $base_dir string Absolute root dir to scanned dir
|
|
|
|
+ * @return array <string> Relative file path to files found
|
|
|
|
+ */
|
|
|
|
+function walk($base_dir) {
|
|
|
|
+ $scan = scandir($base_dir);
|
|
|
|
+ $files = array();
|
|
|
|
+ $blacklisted = array('.', '..', 'class.AutoloaderClassMap.php', 'class.Autoloader.php', 'object');
|
|
|
|
+
|
|
|
|
+ foreach($scan as $elem) {
|
|
|
|
+
|
|
|
|
+ if (in_array($elem, $blacklisted)) continue;
|
|
|
|
+
|
|
|
|
+ if (is_dir($base_dir.'\\'.$elem)) {
|
|
|
|
+
|
|
|
|
+ $deeperFiles = walk($base_dir.'\\'.$elem);
|
|
|
|
+ $deeperFiles = array_reduce( $deeperFiles, function($result, $file) use($elem) {
|
|
|
|
+ $result [] = $elem.SEPARATOR.$file;
|
|
|
|
+ return $result;
|
|
|
|
+ }, array());
|
|
|
|
+
|
|
|
|
+ $files = array_merge($files, $deeperFiles);
|
|
|
|
+
|
|
|
|
+ }else {
|
|
|
|
+ $files [] = $elem;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return $files;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/** Check whether file contains some class
|
|
|
|
+ * @param $filePath string absolute path dir to checked file
|
|
|
|
+ * @return array <string> Class name found
|
|
|
|
+ */
|
|
|
|
+function checkClassExistence($filePath) {
|
|
|
|
+ $tokens = token_get_all( file_get_contents($filePath) );
|
|
|
|
+ $class_token = false;
|
|
|
|
+ $classes = array();
|
|
|
|
+ foreach ($tokens as $token) {
|
|
|
|
+ if ( !is_array($token) ) continue;
|
|
|
|
+ if (in_array($token[0], array(T_CLASS, T_INTERFACE, T_ABSTRACT))) {
|
|
|
|
+ $class_token = true;
|
|
|
|
+ } else if ($class_token && $token[0] == T_STRING) {
|
|
|
|
+ $class_token = false;
|
|
|
|
+ $classes [] = $token[1];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $classes;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+$classFilesDiretories[CLASS_DIR] = array( "files" => walk(CLASS_DIR), "dir" => "");
|
|
|
|
+$classFilesDiretories[API_DIR] = array( "files" => walk(API_DIR), "dir" => "../api");
|
|
|
|
+
|
|
|
|
+$handler = fopen(CLASS_DIR.SEPARATOR."class.AutoloaderClassMap.php", "w");
|
|
|
|
+
|
|
|
|
+$header = "<?php
|
|
|
|
+/**
|
|
|
|
+* This file have been automatically generated by autoloading script
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+class AutoloaderClassMap {
|
|
|
|
+
|
|
|
|
+ public static \$mapClass = array (
|
|
|
|
+
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+$footer = "\t);\n}";
|
|
|
|
+
|
|
|
|
+fwrite($handler, $header);
|
|
|
|
+
|
|
|
|
+foreach ($classFilesDiretories as $classFilesDiretory => $details) {
|
|
|
|
+ foreach ($details['files'] as $classFile) {
|
|
|
|
+ $classes = checkClassExistence( $classFilesDiretory . SEPARATOR . $classFile);
|
|
|
|
+
|
|
|
|
+ foreach ($classes as $class) {
|
|
|
|
+ fwrite($handler, sprintf("\t\t\"%s\" => \"%s\",\n", $class, str_replace('\\', '/', $details['dir'] . SEPARATOR . $classFile)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+fwrite($handler, $footer);
|
|
|
|
+
|
|
|
|
+fclose($handler);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|