Beispiel #1
0
 /**
  * Singleton instance of current class
  */
 public static function getInstance($cache)
 {
     if (!self::$_instance) {
         $pathCache = $cache->load(self::$_cacheIdentifier);
         if ($pathCache) {
             self::$_instance = $pathCache;
         } else {
             self::$_instance = new Zend_Loader_PluginLoader_PathCache($cache);
             $cache->save(self::$_instance);
         }
     }
     return self::$_instance;
 }
Beispiel #2
0
 /**
  * Load a plugin via the name provided
  *
  * @param  string $name
  * @param  bool $throwExceptions Whether or not to throw exceptions if the 
  * class is not resolved
  * @return string|false Class name of loaded class; false if $throwExceptions 
  * if false and no class found
  * @throws Zend_Loader_Exception if class not found
  */
 public function load($name, $throwExceptions = true)
 {
     $name = $this->_formatName($name);
     if ($this->isLoaded($name)) {
         return $this->getClassName($name);
     }
     if ($this->_useStaticRegistry) {
         $registry = self::$_staticPrefixToPaths[$this->_useStaticRegistry];
     } else {
         $registry = $this->_prefixToPaths;
     }
     $registry = array_reverse($registry, true);
     $found = false;
     $classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
     $incFile = self::getIncludeFileCache();
     $cacheLookup = null;
     $cacheHit = false;
     //Start - Will
     # Are we path caching on this instance?
     if (null !== self::$_pathCache) {
         $cache = Zend_Loader_PluginLoader_PathCache::getInstance(self::$_pathCache);
         $cacheLookup = $cache->getPluginPath($name, $registry);
         if (null !== $cacheLookup) {
             $registry = $cacheLookup;
             $cacheHit = true;
         } else {
             //print $classFile;
             //print "cache miss";
         }
     }
     //End - Will
     /*
      * Basically if there is a cached class just use that regardless
      */
     //start will
     /*foreach ($registry as $prefix => $paths)
       {
       	$className = $prefix . $name;
       	if  (class_exists($className, false))
       	{
       		$registry = array();
       		$registry[$prefix] = $name;
       		break;
       	}
       }*/
     //end will
     foreach ($registry as $prefix => $paths) {
         $className = $prefix . $name;
         if (class_exists($className, false)) {
             $found = true;
             if (null !== self::$_pathCache && !$cacheHit) {
                 $cache->logCacheHit($name, $prefix);
             }
             break;
         }
         $paths = array_reverse($paths, true);
         foreach ($paths as $iKey => $path) {
             $loadFile = $path . $classFile;
             if (Zend_Loader::isReadable($loadFile)) {
                 include_once $loadFile;
                 if (class_exists($className, false)) {
                     if (null !== $incFile) {
                         self::_appendIncFile($loadFile);
                     }
                     //Start - Will
                     if (null !== self::$_pathCache && !$cacheHit) {
                         $cache->logCacheHit($name, $prefix, $path);
                     }
                     //End - Will
                     $found = true;
                     break 2;
                 }
             }
             //Start - Will
             if (null !== self::$_pathCache) {
                 $cache->logCacheMiss($name, $prefix, $path);
             }
             //End - Will
         }
     }
     if (!$found) {
         if (!$throwExceptions) {
             return false;
         }
         $message = "Plugin by name '{$name}' was not found in the registry; used paths:";
         foreach ($registry as $prefix => $paths) {
             $message .= "\n{$prefix}: " . implode(PATH_SEPARATOR, $paths);
         }
         ////require_once 'Zend/Loader/PluginLoader/Exception.php';
         throw new Zend_Loader_PluginLoader_Exception($message);
     }
     if ($this->_useStaticRegistry) {
         self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name] = $className;
         self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name] = isset($loadFile) ? $loadFile : '';
     } else {
         $this->_loadedPlugins[$name] = $className;
         $this->_loadedPluginPaths[$name] = isset($loadFile) ? $loadFile : '';
     }
     return $className;
 }