Skip to content

Commit

Permalink
renamed some UniversalClassLoader for better consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 31, 2011
1 parent 02605f3 commit 28527c7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ timeline closely anyway.
beta3 to beta4
--------------

* Some `UniversalClassLoader` methods have been renamed:

* `registerPrefixFallback` to `registerPrefixFallbacks`
* `registerNamespaceFallback` to `registerNamespaceFallbacks`

* The event system has been made more flexible. A listener can now be any
valid PHP callable.

Expand Down
4 changes: 2 additions & 2 deletions autoload.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $loader->registerPrefixes(array(
'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes',
'Twig_' => __DIR__.'/vendor/twig/lib',
));
$loader->register();
$loader->registerPrefixFallback(array(
$loader->registerPrefixFallbacks(array(
__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs',
));
$loader->register();
28 changes: 14 additions & 14 deletions src/Symfony/Component/ClassLoader/UniversalClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class UniversalClassLoader
{
private $namespaces = array();
private $prefixes = array();
private $namespaceFallback = array();
private $prefixFallback = array();
private $namespaceFallbacks = array();
private $prefixFallbacks = array();

/**
* Gets the configured namespaces.
Expand All @@ -86,43 +86,43 @@ public function getPrefixes()
*
* @return array An array of directories
*/
public function getNamespaceFallback()
public function getNamespaceFallbacks()
{
return $this->namespaceFallback;
return $this->namespaceFallbacks;
}

/**
* Gets the directory(ies) to use as a fallback for class prefixes.
*
* @return array An array of directories
*/
public function getPrefixFallback()
public function getPrefixFallbacks()
{
return $this->prefixFallback;
return $this->prefixFallbacks;
}

/**
* Registers the directory to use as a fallback for namespaces.
*
* @param string|array $dirs A directory path or an array of directories
* @param array $dirs An array of directories
*
* @api
*/
public function registerNamespaceFallback($dirs)
public function registerNamespaceFallbacks(array $dirs)
{
$this->namespaceFallback = (array) $dirs;
$this->namespaceFallbacks = $dirs;
}

/**
* Registers the directory to use as a fallback for class prefixes.
*
* @param string|array $dirs A directory path or an array of directories
* @param array $dirs An array of directories
*
* @api
*/
public function registerPrefixFallback($dirs)
public function registerPrefixFallbacks(array $dirs)
{
$this->prefixFallback = (array) $dirs;
$this->prefixFallbacks = $dirs;
}

/**
Expand Down Expand Up @@ -231,7 +231,7 @@ public function findFile($class)
}
}

foreach ($this->namespaceFallback as $dir) {
foreach ($this->namespaceFallbacks as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
if (file_exists($file)) {
return $file;
Expand All @@ -250,7 +250,7 @@ public function findFile($class)
}
}

foreach ($this->prefixFallback as $dir) {
foreach ($this->prefixFallbacks as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
if (file_exists($file)) {
return $file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function testLoadClassFromFallback($className, $testClassName, $message)
$loader = new UniversalClassLoader();
$loader->registerNamespace('Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
$loader->registerPrefix('Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
$loader->registerNamespaceFallback(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback');
$loader->registerPrefixFallback(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback');
$loader->registerNamespaceFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'));
$loader->registerPrefixFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'));
$loader->loadClass($testClassName);
$this->assertTrue(class_exists($className), $message);
}
Expand Down

0 comments on commit 28527c7

Please sign in to comment.