Beispiel #1
0
 /**
  * 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;
 }
 /**
  * Initialization
  * @param bool $force whether to force initialization
  * @return bool
  * @throws epExceptionManagerBase
  */
 protected function initialize($force = false)
 {
     // done if not forced, and class map and db factories are set
     if (!$force && $this->cmf && $this->dbf) {
         return true;
     }
     // get the runtime class map file
     if (!($rcmf = $this->getConfigOption('compiled_file'))) {
         throw new epExceptionManagerBase('Runtime class map 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);
         }
     }
     // unserializing class map file into class map factory
     include_once EP_SRC_ORM . '/epClassMap.php';
     // get the contetns of the runtime config map file
     $runtime_map_content = false;
     if (file_exists($rcmf)) {
         $runtime_map_content = file_get_contents($rcmf);
     }
     // if compiled runtime map content exists and config file is older than compiled
     if ($runtime_map_content && filemtime($this->getConfigSource()) < filemtime($rcmf)) {
         // unserialize class map info
         $this->cmf =& epClassMapFactory::unserialize($runtime_map_content);
         if (!$this->cmf) {
             throw new epExceptionManagerBase('Cannot unserialize runtime class mapping info');
             return false;
         }
         // need to recompile new class files
         $this->_compileAll();
     } else {
         // if no compiled class map file found, simply get the class map factory instance
         $this->cmf =& epClassMapFactory::instance();
         // remove all classes now
         $this->cmf->removeAll();
         // check if the source dir is set
         if ($source_dirs = $this->getConfigOption('source_dirs')) {
             // compile all if so
             $this->_compileAll();
         }
     }
     // get the db factory
     include_once EP_SRC_DB . '/epDbObject.php';
     if (!($this->dbf =& epDbFactory::instance())) {
         throw new epExceptionManagerBase('Cannot get db factory instance');
         return false;
     }
     // remove all connections
     $this->dbf->removeAll();
     // set the db lib to use
     $this->dbf->setDbLib($this->getConfigOption('db_lib'));
     return true;
 }