/** * test container functions of classs map */ function testClassMapContainer() { // get the singleton class map factory $cmf =& epClassMapFactory::instance(); $this->assertTrue(isset($cmf)); // create a class map $cm_tb =& $cmf->make('epTestBase'); $this->assertTrue(isset($cm_tb)); // create class map children $num_children = 100; for ($i = 0; $i < $num_children; $i++) { // create class map 1 $child_name = sprintf('epTest%03d', $i); $cm_t =& $cmf->make($child_name); $this->assertTrue(isset($cm_t)); $this->assertTrue($cm_tb !== $cm_t); $cm_t->setParent($cm_tb); $this->assertTrue($cm_tb->addChild($cm_t)); } // check parent-child relationship $children = $cm_tb->getChildren(false, true); // false: non-recursive; true: sort $this->assertTrue(count($children) == $num_children); $i = 0; foreach ($children as $child) { $parent =& $child->getParent(); $this->assertTrue(isset($parent)); $this->assertTrue($parent->getName() == 'epTestBase'); $child_name = sprintf('epTest%03d', $i); $this->assertTrue($child->getName() == $child_name); $i++; } }
/** * Loads compiled info into manager * * According to compile options, 'force_compile' and 'auto_compile', * the method decides whether to recompile all or some of the class * files. * * @return boolean */ protected function _loadCompiled() { // get the compiled info if (!($rcmf = $this->getConfigOption('compiled_file'))) { throw new epExceptionManagerBase('Compiled file not specified'); return false; } // get the dir that holds the class map file if ($compiled_dir = $this->getConfigOption('compiled_dir')) { // if compiled dir is a relative path, make is absolute $compiled_dir = $this->getAbsolutePath($compiled_dir); $rcmf = $compiled_dir . '/' . $rcmf; } // check if force_compile is set if ($this->getConfigOption('force_compile')) { // if so, delete the compiled file to force compile if (file_exists($rcmf)) { @unlink($rcmf); } } // get the contetns of the runtime config map file $compiled_info = false; if (file_exists($rcmf)) { $compiled_info = file_get_contents($rcmf); } // unserializing compiled info into class map factory include_once EP_SRC_ORM . '/epClassMap.php'; if ($compiled_info) { // unserialize class map info $this->cmf =& epClassMapFactory::unserialize($compiled_info); if (!$this->cmf) { throw new epExceptionManagerBase('Cannot unserialize compiled info'); return false; } // only when auto compile do we check config file mtime if ($this->getConfigOption('auto_compile')) { // if config file is newer than compiled info if (filemtime($this->getConfigSource()) > filemtime($rcmf)) { // remove all classes to force recompile $this->cmf->removeAll(); } } } else { // simply get the class map factory instance $this->cmf =& epClassMapFactory::instance(); // remove all classes now $this->cmf->removeAll(); } // check if auto_compile is enabled if ($this->getConfigOption('auto_compile')) { $this->_compileAll(); } return true; }
/** * Destroy singletons to force reconstruction */ function _destroy() { // destroy class map factory include_once EP_SRC_ORM . '/epClassMap.php'; epClassMapFactory::destroy(); // destroy db connections include_once EP_SRC_DB . '/epDbObject.php'; epDbFactory::destroy(); // destroy manager include_once EP_SRC_RUNTIME . '/epManager.php'; epManager::destroy(); }
/** * Implement {@link epSingleton} interface * Forcefully destroy old instance (only used for tests). * After reset(), {@link instance()} returns a new instance. */ public static function destroy() { self::$instance = null; }
/** * Handles PS_CLASS_EXTENDS_NAME * @param string $symbol * @param mixed $payload (unused) * @return void */ public function classExtendsHandler($symbol, $payload) { // skip the current class? if ($this->skip_class) { return; } // get the parent class name $super_class = $this->token[1]; if (!$super_class) { throw new epExceptionParser('Empty superclass name in parsing'); return; } // build a class map with class name $cm_super =& $this->cmf->make($super_class); // warn if class map not created (should not happen) if (!$cm_super) { throw new epExceptionParser('Cannot create class map for ' . $class); return; } // set parent-child $this->cm->setParent($cm_super); $cm_super->addChild($this->cm); }
/** * Filter a given array of input files and returns only * the newly modifed after last compile and those files * that have not been compiled * * @param array $input_files * @return array */ protected function getNewFiles($input_files) { // get class map factory if (!($cmf = epClassMapFactory::instance())) { return $input_files; } // get all class maps if (!($cms = $cmf->allMade())) { // recompile all if no class map found at all return $input_files; } // arrays to keep track of new files to parse $new_files = array(); // arrays to keep track of files compiled $compiled_files = array(); // go through each foreach ($cms as &$cm) { // get the source file if (!($f = $cm->getClassFile())) { continue; } // is file in input files? if (in_array($f, $input_files) && !in_array($f, $compiled_files)) { // a file that's been compiled $compiled_files[] = $f; } // skip classes no need to compile if ($cm->needRecompile() && !in_array($f, $new_files)) { $new_files[] = $f; } } // now get the uncompiled files $uncompiled_files = array_diff($input_files, $compiled_files); // return both uncompiled files and new files return array_merge($new_files, $uncompiled_files); }
/** * Debug: Print out all class maps in the factory */ function _cmfToString(epClassMapFactory $cmf) { $s = ''; $cms = $cmf->allMade(); ksort($cms); foreach ($cms as $cm) { $s .= 'class: ' . $cm->getName() . epNewLine(); $fms = $cm->getAllFields(); ksort($fms); foreach ($fms as $fm) { $s .= ' field: ' . $fm->getName() . epNewLine(); } } return $s; }
/** * Constructor * @param epConfig|array * @access public * @see epConfig */ public function __construct($config = null) { parent::__construct($config); $this->cmf = epClassMapFactory::instance(); }
/** * Create all tables for classes mapped so far * (This method may be useful if you want to create tables all at once) * @return false|array (of classes for which tables are created) * @access public */ public function createTables() { // if class map factory does not exist yet if (!$this->cmf) { // initialize $this->initialize(true); } // go through all classes mapped $class_tables = array(); if ($cms = $this->cmf->allMade()) { foreach ($cms as $cm) { if ($this->_getDb($cm->getName(), $cm)) { $class_tables[$cm->getName()] = $cm; } } } return $class_tables; }