Permalink
Browse files

Add flag for autoregistering Zend prefix (merge r24982)

- By default, no longer auto-registers Zend_ prefix
- Can autoregister by passing flag to constructor or setOptions():
  array('autoregister_zf' => true)



git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@24984 44c647ce-9c0f-0410-b52a-842ac1e357ba
  • Loading branch information...
1 parent 88320b6 commit 1bec993bc39b960a799f4245b94f3a89e2946d41 matthew committed Jun 19, 2012
Showing with 22 additions and 7 deletions.
  1. +6 −7 library/Zend/Loader/StandardAutoloader.php
  2. +16 −0 tests/Zend/Loader/StandardAutoloaderTest.php
@@ -39,6 +39,7 @@ class Zend_Loader_StandardAutoloader implements Zend_Loader_SplAutoloader
const LOAD_NS = 'namespaces';
const LOAD_PREFIX = 'prefixes';
const ACT_AS_FALLBACK = 'fallback_autoloader';
+ const AUTOREGISTER_ZF = 'autoregister_zf';
/**
* @var array Namespace/directory pairs to search; ZF library added by default
@@ -68,13 +69,6 @@ class Zend_Loader_StandardAutoloader implements Zend_Loader_SplAutoloader
*/
public function __construct($options = null)
{
- $this->registerPrefix('Zend', dirname(dirname(__FILE__)));
-
- $zfDir = dirname(dirname(dirname(__FILE__))) . '/Zend';
- if (file_exists($zfDir)) {
- $this->registerPrefix('Zend', $zfDir);
- }
-
if (null !== $options) {
$this->setOptions($options);
}
@@ -110,6 +104,11 @@ public function setOptions($options)
foreach ($options as $type => $pairs) {
switch ($type) {
+ case self::AUTOREGISTER_ZF:
+ if ($pairs) {
+ $this->registerPrefix('Zend', dirname(dirname(__FILE__)));
+ }
+ break;
case self::LOAD_NS:
if (is_array($pairs) || $pairs instanceof Traversable) {
$this->registerNamespaces($pairs);
@@ -199,6 +199,22 @@ public function testAutoloadsNamespacedClassesWithUnderscores()
$loader->autoload('ZendTest\UnusualNamespace\Name_Space\Namespaced_Class');
$this->assertTrue(class_exists('ZendTest\UnusualNamespace\Name_Space\Namespaced_Class', false));
}
+
+ public function testZendFrameworkPrefixIsNotLoadedByDefault()
+ {
+ $loader = new Zend_Loader_StandardAutoloader();
+ $expected = array();
+ $this->assertAttributeEquals($expected, 'prefixes', $loader);
+ }
+
+ public function testCanTellAutoloaderToRegisterZfPrefixAtInstantiation()
+ {
+ $loader = new Zend_Loader_StandardAutoloader(array('autoregister_zf' => true));
+ $r = new ReflectionClass($loader);
+ $file = $r->getFileName();
+ $expected = array('Zend_' => dirname(dirname($file)) . DIRECTORY_SEPARATOR);
+ $this->assertAttributeEquals($expected, 'prefixes', $loader);
+ }
}
if (PHPUnit_MAIN_METHOD == 'Zend_Loader_StandardAutoloaderTest::main') {

0 comments on commit 1bec993

Please sign in to comment.