Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Added unregisterAutoloader($autoloaderClass) method
Browse files Browse the repository at this point in the history
- Allow unregistering a single autoloader at a time
  • Loading branch information
weierophinney committed Oct 3, 2011
1 parent e156020 commit 4fb9db5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/AutoloaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public static function getRegisteredAutoloaders()
return static::$loaders;
}


/**
* Retrieves an autoloader by class name
*
Expand Down Expand Up @@ -138,6 +137,24 @@ public static function unregisterAutoloaders()
}
}

/**
* Unregister a single autoloader by class name
*
* @param string $autoloaderClass
* @return bool
*/
public static function unregisterAutoloader($autoloaderClass)
{
if (!isset(static::$loaders[$autoloaderClass])) {
return false;
}

$autoloader = static::$loaders[$autoloaderClass];
spl_autoload_unregister(array($autoloader, 'autoload'));
unset(static::$loaders[$autoloaderClass]);
return true;
}

/**
* Get an instance of the standard autoloader
*
Expand Down
13 changes: 13 additions & 0 deletions test/AutoloaderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ public function testCanUnregisterAutoloaders()
$this->assertEquals(0, count(AutoloaderFactory::getRegisteredAutoloaders()));
}

public function testCanUnregisterAutoloadersByClassName()
{
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
'TestNamespace' => __DIR__ . '/TestAsset/TestNamespace',
),
),
));
AutoloaderFactory::unregisterAutoloader('Zend\Loader\StandardAutoloader');
$this->assertEquals(0, count(AutoloaderFactory::getRegisteredAutoloaders()));
}

public function testCanGetValidRegisteredAutoloader()
{
AutoloaderFactory::factory(array(
Expand Down

0 comments on commit 4fb9db5

Please sign in to comment.