equal
deleted
inserted
replaced
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Loader |
16 * @package Zend_Loader |
17 * @subpackage PluginLoader |
17 * @subpackage PluginLoader |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: PluginLoader.php 24877 2012-06-04 14:04:53Z adamlundrigan $ |
20 * @version $Id$ |
21 */ |
21 */ |
22 |
22 |
23 /** Zend_Loader_PluginLoader_Interface */ |
23 /** Zend_Loader_PluginLoader_Interface */ |
24 require_once 'Zend/Loader/PluginLoader/Interface.php'; |
24 require_once 'Zend/Loader/PluginLoader/Interface.php'; |
25 |
25 |
30 * Generic plugin class loader |
30 * Generic plugin class loader |
31 * |
31 * |
32 * @category Zend |
32 * @category Zend |
33 * @package Zend_Loader |
33 * @package Zend_Loader |
34 * @subpackage PluginLoader |
34 * @subpackage PluginLoader |
35 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
35 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
37 */ |
37 */ |
38 class Zend_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface |
38 class Zend_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface |
39 { |
39 { |
40 /** |
40 /** |
42 * @var string |
42 * @var string |
43 */ |
43 */ |
44 protected static $_includeFileCache; |
44 protected static $_includeFileCache; |
45 |
45 |
46 /** |
46 /** |
|
47 * Class map cache file handler |
|
48 * @var resource |
|
49 */ |
|
50 protected static $_includeFileCacheHandler; |
|
51 |
|
52 /** |
47 * Instance loaded plugin paths |
53 * Instance loaded plugin paths |
48 * |
54 * |
49 * @var array |
55 * @var array |
50 */ |
56 */ |
51 protected $_loadedPluginPaths = array(); |
57 protected $_loadedPluginPaths = array(); |
126 if($prefix == "") { |
132 if($prefix == "") { |
127 return $prefix; |
133 return $prefix; |
128 } |
134 } |
129 |
135 |
130 $nsSeparator = (false !== strpos($prefix, '\\'))?'\\':'_'; |
136 $nsSeparator = (false !== strpos($prefix, '\\'))?'\\':'_'; |
131 return rtrim($prefix, $nsSeparator) . $nsSeparator; |
137 $prefix = rtrim($prefix, $nsSeparator) . $nsSeparator; |
|
138 //if $nsSeprator == "\" and the prefix ends in "_\" remove trailing \ |
|
139 //https://github.com/zendframework/zf1/issues/152 |
|
140 if(($nsSeparator == "\\") && (substr($prefix,-2) == "_\\")) { |
|
141 $prefix = substr($prefix, 0, -1); |
|
142 } |
|
143 return $prefix; |
132 } |
144 } |
133 |
145 |
134 /** |
146 /** |
135 * Add prefixed paths to the registry of paths |
147 * Add prefixed paths to the registry of paths |
136 * |
148 * |
430 * @return void |
442 * @return void |
431 * @throws Zend_Loader_PluginLoader_Exception if file is not writeable or path does not exist |
443 * @throws Zend_Loader_PluginLoader_Exception if file is not writeable or path does not exist |
432 */ |
444 */ |
433 public static function setIncludeFileCache($file) |
445 public static function setIncludeFileCache($file) |
434 { |
446 { |
|
447 if (!empty(self::$_includeFileCacheHandler)) { |
|
448 flock(self::$_includeFileCacheHandler, LOCK_UN); |
|
449 fclose(self::$_includeFileCacheHandler); |
|
450 } |
|
451 |
|
452 self::$_includeFileCacheHandler = null; |
|
453 |
435 if (null === $file) { |
454 if (null === $file) { |
436 self::$_includeFileCache = null; |
455 self::$_includeFileCache = null; |
437 return; |
456 return; |
438 } |
457 } |
439 |
458 |
469 * @param string $incFile |
488 * @param string $incFile |
470 * @return void |
489 * @return void |
471 */ |
490 */ |
472 protected static function _appendIncFile($incFile) |
491 protected static function _appendIncFile($incFile) |
473 { |
492 { |
474 if (!file_exists(self::$_includeFileCache)) { |
493 if (!isset(self::$_includeFileCacheHandler)) { |
475 $file = '<?php'; |
494 self::$_includeFileCacheHandler = fopen(self::$_includeFileCache, 'ab'); |
476 } else { |
495 |
477 $file = file_get_contents(self::$_includeFileCache); |
496 if (!flock(self::$_includeFileCacheHandler, LOCK_EX | LOCK_NB, $wouldBlock) || $wouldBlock) { |
478 } |
497 self::$_includeFileCacheHandler = false; |
479 if (!strstr($file, $incFile)) { |
498 } |
480 $file .= "\ninclude_once '$incFile';"; |
499 } |
481 file_put_contents(self::$_includeFileCache, $file); |
500 |
|
501 if (false !== self::$_includeFileCacheHandler) { |
|
502 $line = "<?php include_once '$incFile'?>\n"; |
|
503 fwrite(self::$_includeFileCacheHandler, $line, strlen($line)); |
482 } |
504 } |
483 } |
505 } |
484 } |
506 } |