<?php require_once '../lib/dynamic_autoloader/ClassFileMapFactory.php'; require_once '../lib/dynamic_autoloader/ClassFileMapAutoloader.php'; // Set up the include path define('BASE_PATH', realpath(dirname(__FILE__) . '/..')); set_include_path(BASE_PATH . PATH_SEPARATOR . get_include_path()); $lib_class_map = ClassFileMapFactory::generate("../"); $_autoloader = new ClassFileMapAutoloader(); $_autoloader->addClassFileMap($lib_class_map); $data = serialize($_autoloader); if (file_put_contents("../classmap.ser", $data)) { echo "OK<br>"; } else { echo "FAILED<br>"; } echo "Found " . count($lib_class_map->getClassMap()) . " classes :<br>"; echo '<table border="1"><thead><tr><th align="left">Class</th><th align="left">Path</th></tr></thead><tbody>'; foreach ($lib_class_map->getClassMap() as $key => $file) { echo "<tr><td>{$key}</td><td>{$file}</td></tr>"; } echo "</tbody></table>\n";
public static function createClassMap() { //require_once('../lib/dynamic_autoloader/ClassFileMapFactory.php'); //require_once('../lib/dynamic_autoloader/ClassFileMapAutoloader.php'); // Set up the include path //define('BASE_PATH', realpath(dirname(__FILE__).'/..')); //set_include_path(BASE_PATH.PATH_SEPARATOR.get_include_path()); // TODO check classmap.ser permissions $classmap = Constants::$codevRootDir . '/classmap.ser'; $classmapCopy = Constants::$codevRootDir . '/classmap.ser.old'; if (!is_writable($classmap)) { throw new Exception("Please check write permissions to {$classmap}"); } // save previous classmap.ser file if (!rename($classmap, $classmapCopy)) { $errorRename = "Failed to rename " . $classmap . " into " . $classmapCopy; self::$logger->error($errorRename); //throw new Exception($errorRename); } // reload classmap, so that new classes are accessible $lib_class_map = ClassFileMapFactory::generate(Constants::$codevRootDir); $_autoloader = new ClassFileMapAutoloader(); $_autoloader->addClassFileMap($lib_class_map); $_autoloader->registerAutoload(); // write new classmap to file $data = serialize($_autoloader); if (!file_put_contents(Constants::$codevRootDir . '/classmap.ser', $data)) { if (!file_exists($classmapCopy)) { throw new Exception("Classmap creation failed + no backup file found for " . $classmap); } if (!rename($classmapCopy, $classmap)) { throw new Exception("Classmap creation failed + could not revert to " . $classmapCopy); } else { throw new Exception("Classmap creation failed, previous classmap restored."); } } }