[ClassLoader] Add ability to incrementally register fallbacks.
This is useful in the cases where you might be adding forward compat classes to several components.
This commit is contained in:
parent
74ebd057a1
commit
d339e74bc5
@ -141,7 +141,17 @@ class UniversalClassLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the directory to use as a fallback for class prefixes.
|
||||
* Registers a directory to use as a fallback for namespaces.
|
||||
*
|
||||
* @param string $dir A directory
|
||||
*/
|
||||
public function registerNamespaceFallback($dir)
|
||||
{
|
||||
$this->namespaceFallbacks[] = $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers directories to use as a fallback for class prefixes.
|
||||
*
|
||||
* @param array $dirs An array of directories
|
||||
*
|
||||
@ -152,6 +162,16 @@ class UniversalClassLoader
|
||||
$this->prefixFallbacks = $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a directory to use as a fallback for class prefixes.
|
||||
*
|
||||
* @param string $dir A directory
|
||||
*/
|
||||
public function registerPrefixFallback($dir)
|
||||
{
|
||||
$this->prefixFallbacks[] = $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an array of namespaces
|
||||
*
|
||||
|
@ -80,6 +80,20 @@ class UniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testRegisterPrefixFallback()
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerPrefixFallback(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback');
|
||||
$this->assertEquals(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'), $loader->getPrefixFallbacks());
|
||||
}
|
||||
|
||||
public function testRegisterNamespaceFallback()
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerNamespaceFallback(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Namespaced/fallback');
|
||||
$this->assertEquals(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Namespaced/fallback'), $loader->getNamespaceFallbacks());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassNamespaceCollisionTests
|
||||
*/
|
||||
|
Reference in New Issue
Block a user