24 #require_once 'Zend/Loader/PluginLoader/Interface.php'; 27 #require_once 'Zend/Loader.php'; 44 protected static $_includeFileCache;
50 protected static $_includeFileCacheHandler;
57 protected $_loadedPluginPaths = array();
64 protected $_loadedPlugins = array();
71 protected $_prefixToPaths = array();
78 protected static $_staticLoadedPluginPaths = array();
85 protected static $_staticLoadedPlugins = array();
92 protected static $_staticPrefixToPaths = array();
99 protected $_useStaticRegistry =
null;
107 public function __construct(Array $prefixToPaths = array(), $staticRegistryName =
null)
109 if (is_string($staticRegistryName) && !empty($staticRegistryName)) {
110 $this->_useStaticRegistry = $staticRegistryName;
111 if(!isset(self::$_staticPrefixToPaths[$staticRegistryName])) {
112 self::$_staticPrefixToPaths[$staticRegistryName] = array();
114 if(!isset(self::$_staticLoadedPlugins[$staticRegistryName])) {
115 self::$_staticLoadedPlugins[$staticRegistryName] = array();
130 protected function _formatPrefix(
$prefix)
136 $nsSeparator = (
false !== strpos(
$prefix,
'\\'))?
'\\':
'_';
140 if(($nsSeparator ==
"\\") && (substr(
$prefix,-2) ==
"_\\")) {
156 #require_once 'Zend/Loader/PluginLoader/Exception.php'; 163 if ($this->_useStaticRegistry) {
164 self::$_staticPrefixToPaths[$this->_useStaticRegistry][
$prefix][] =
$path;
166 if (!isset($this->_prefixToPaths[
$prefix])) {
167 $this->_prefixToPaths[
$prefix] = array();
182 public function getPaths(
$prefix =
null)
186 if ($this->_useStaticRegistry) {
187 if (isset(self::$_staticPrefixToPaths[$this->_useStaticRegistry][
$prefix])) {
188 return self::$_staticPrefixToPaths[$this->_useStaticRegistry][
$prefix];
194 if (isset($this->_prefixToPaths[
$prefix])) {
195 return $this->_prefixToPaths[
$prefix];
201 if ($this->_useStaticRegistry) {
202 return self::$_staticPrefixToPaths[$this->_useStaticRegistry];
205 return $this->_prefixToPaths;
214 public function clearPaths(
$prefix =
null)
218 if ($this->_useStaticRegistry) {
219 if (isset(self::$_staticPrefixToPaths[$this->_useStaticRegistry][
$prefix])) {
220 unset(self::$_staticPrefixToPaths[$this->_useStaticRegistry][
$prefix]);
227 if (isset($this->_prefixToPaths[
$prefix])) {
228 unset($this->_prefixToPaths[
$prefix]);
235 if ($this->_useStaticRegistry) {
236 self::$_staticPrefixToPaths[$this->_useStaticRegistry] = array();
238 $this->_prefixToPaths = array();
254 if ($this->_useStaticRegistry) {
255 $registry =& self::$_staticPrefixToPaths[$this->_useStaticRegistry];
261 #require_once 'Zend/Loader/PluginLoader/Exception.php'; 267 if (
false ===
$pos) {
268 #require_once 'Zend/Loader/PluginLoader/Exception.php'; 285 protected function _formatName(
$name)
287 return ucfirst((
string)
$name);
299 if ($this->_useStaticRegistry) {
300 return isset(self::$_staticLoadedPlugins[$this->_useStaticRegistry][
$name]);
303 return isset($this->_loadedPlugins[
$name]);
315 if ($this->_useStaticRegistry
316 && isset(self::$_staticLoadedPlugins[$this->_useStaticRegistry][
$name])
318 return self::$_staticLoadedPlugins[$this->_useStaticRegistry][
$name];
320 return $this->_loadedPlugins[
$name];
332 public function getClassPath(
$name)
335 if ($this->_useStaticRegistry
336 && !empty(self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][
$name])
338 return self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][
$name];
339 }
elseif (!empty($this->_loadedPluginPaths[
$name])) {
340 return $this->_loadedPluginPaths[
$name];
345 $r =
new ReflectionClass(
$class);
346 $path = $r->getFileName();
347 if ($this->_useStaticRegistry) {
348 self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][
$name] =
$path;
368 public function load(
$name, $throwExceptions =
true)
375 if ($this->_useStaticRegistry) {
376 $registry = self::$_staticPrefixToPaths[$this->_useStaticRegistry];
383 if (
false !== strpos(
$name,
'\\')) {
384 $classFile = str_replace(
'\\', DIRECTORY_SEPARATOR,
$name) .
'.php';
386 $classFile = str_replace(
'_', DIRECTORY_SEPARATOR,
$name) .
'.php';
388 $incFile = self::getIncludeFileCache();
400 $loadFile =
$path . $classFile;
402 include_once $loadFile;
404 if (
null !== $incFile) {
405 self::_appendIncFile($loadFile);
415 if (!$throwExceptions) {
419 $message =
"Plugin by name '$name' was not found in the registry; used paths:";
423 #require_once 'Zend/Loader/PluginLoader/Exception.php'; 427 if ($this->_useStaticRegistry) {
428 self::$_staticLoadedPlugins[$this->_useStaticRegistry][
$name] =
$className;
445 public static function setIncludeFileCache($file)
447 if (!empty(self::$_includeFileCacheHandler)) {
448 flock(self::$_includeFileCacheHandler, LOCK_UN);
449 fclose(self::$_includeFileCacheHandler);
452 self::$_includeFileCacheHandler =
null;
454 if (
null === $file) {
455 self::$_includeFileCache =
null;
459 if (!file_exists($file) && !file_exists(dirname($file))) {
460 #require_once 'Zend/Loader/PluginLoader/Exception.php'; 464 #require_once 'Zend/Loader/PluginLoader/Exception.php'; 467 if (!file_exists($file) && file_exists(dirname($file)) && !
is_writable(dirname($file))) {
468 #require_once 'Zend/Loader/PluginLoader/Exception.php'; 472 self::$_includeFileCache = $file;
480 public static function getIncludeFileCache()
482 return self::$_includeFileCache;
491 protected static function _appendIncFile($incFile)
493 if (!isset(self::$_includeFileCacheHandler)) {
494 self::$_includeFileCacheHandler =
fopen(self::$_includeFileCache,
'ab');
496 if (!flock(self::$_includeFileCacheHandler, LOCK_EX | LOCK_NB, $wouldBlock) || $wouldBlock) {
497 self::$_includeFileCacheHandler =
false;
501 if (
false !== self::$_includeFileCacheHandler) {
502 $line =
"<?php include_once '$incFile'?>\n";
503 fwrite(self::$_includeFileCacheHandler, $line, strlen($line));
elseif(isset( $params[ 'redirect_parent']))
static isReadable($filename)
$_option $_optionId $class
addPrefixPath($prefix, $path)
removePrefixPath($prefix, $path=null)
if(!isset($_GET['name'])) $name