Skip to content

Commit

Permalink
[ClassLoader] Add ability to incrementally register fallbacks.
Browse files Browse the repository at this point in the history
This is useful in the cases where you might be adding forward compat
classes to several components.
  • Loading branch information
Drak committed Feb 22, 2012
1 parent 74ebd05 commit d339e74
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Symfony/Component/ClassLoader/UniversalClassLoader.php
Expand Up @@ -141,7 +141,17 @@ public function registerNamespaceFallbacks(array $dirs)
}

/**
* 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
*
Expand All @@ -152,6 +162,16 @@ public function registerPrefixFallbacks(array $dirs)
$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
*
Expand Down
Expand Up @@ -80,6 +80,20 @@ public function getLoadClassFromFallbackTests()
);
}

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
*/
Expand Down

0 comments on commit d339e74

Please sign in to comment.