Ejemplo n.º 1
0
 public static function &getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new __CacheManager();
     }
     return self::$_instance;
 }
Ejemplo n.º 2
0
 protected function _loadClassLocations()
 {
     //normalize the base dir:
     $this->_normalized_basedir = rtrim($this->_base_dir, DIRECTORY_SEPARATOR);
     //load the classes:
     $debug_mode = __Lion::getInstance()->getRuntimeDirectives()->getDirective('DEBUG_MODE');
     if (!$debug_mode) {
         $this->_metadata = __CacheManager::getInstance()->getCache()->getData('classloader_' . $this->_normalized_basedir);
     }
     if ($this->_metadata == null) {
         $this->_metadata = $this->_loadMetadata();
         if (!$debug_mode) {
             __CacheManager::getInstance()->getCache()->setData('classloader_' . $this->_normalized_basedir, $this->_metadata);
         }
     }
     $this->_mapping = $this->_metadata['mapping'];
     $this->_autoloaders = $this->_metadata['autoloaders'];
     $this->_classpaths = $this->_metadata['classpaths'];
 }
 public function &createContext($context_id, $context_base_dir, $configuration_file = null)
 {
     if ($this->hasContext($context_id)) {
         throw __ExceptionFactory::getInstance()->createException('Context already exists for context identifier ' . $context_id);
     }
     //create a class file locator for the context to create to
     $class_file_locator = new __ClassFileLocator($context_base_dir);
     __ClassLoader::getInstance()->addClassFileLocator($class_file_locator);
     //scann in depth starting from configuration location before scanning the context basedir
     if ($configuration_file != null) {
         $configuration_base_dir = dirname($configuration_file);
         if (strpos($configuration_base_dir, $context_base_dir) === false) {
             $configuration_class_file_locator = new __ClassFileLocator($configuration_base_dir);
             __ClassLoader::getInstance()->addClassFileLocator($configuration_class_file_locator);
         }
     }
     //do not read nor store into the cache the initial context in case of DEBUG_MODE active:
     if (__Lion::getInstance()->getRuntimeDirectives()->getDirective('DEBUG_MODE')) {
         $cache = null;
         //by default
         $context = null;
     } else {
         $cache = __CacheManager::getInstance()->getCache();
         $context = $cache->getData('__Context__' . $context_id);
         if ($context != null) {
             $this->_addContext($context);
         }
     }
     //if no context has been read from cache:
     if ($context == null) {
         $context = new __Context($context_id, $context_base_dir);
         $this->_addContext($context);
         $context->loadConfiguration($configuration_file);
         if ($cache != null) {
             $cache->setData('__Context__' . $context_id, $context);
         }
     }
     //Startup the context
     $context->startup();
     //return a reference to the already created context:
     return $context;
 }
Ejemplo n.º 4
0
 /**
  * Gets the cache associated to current context
  *
  * @return __Cache
  */
 public function &getCache()
 {
     //cache is shared between all contexts:
     return __CacheManager::getInstance()->getCache();
 }