diff --git a/src/Symfony/Component/ClassLoader/ApcClassLoader.php b/src/Symfony/Component/ClassLoader/ApcClassLoader.php index 48de72f1b11f8..b97b8a261c536 100644 --- a/src/Symfony/Component/ClassLoader/ApcClassLoader.php +++ b/src/Symfony/Component/ClassLoader/ApcClassLoader.php @@ -16,8 +16,8 @@ * * It expects an object implementing a findFile method to find the file. This * allows using it as a wrapper around the other loaders of the component (the - * ClassLoader and the UniversalClassLoader for instance) but also around any - * other autoloaders following this convention (the Composer one for instance). + * ClassLoader for instance) but also around any other autoloaders following + * this convention (the Composer one for instance). * * // with a Symfony autoloader * use Symfony\Component\ClassLoader\ClassLoader; diff --git a/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php b/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php deleted file mode 100644 index dd95413caf100..0000000000000 --- a/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php +++ /dev/null @@ -1,105 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\ClassLoader; - -trigger_error('The '.__NAMESPACE__.'\ApcUniversalClassLoader class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Component\ClassLoader\ApcClassLoader class instead.', E_USER_DEPRECATED); - -/** - * ApcUniversalClassLoader implements a "universal" autoloader cached in APC for PHP 5.3. - * - * It is able to load classes that use either: - * - * * The technical interoperability standards for PHP 5.3 namespaces and - * class names (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md); - * - * * The PEAR naming convention for classes (http://pear.php.net/). - * - * Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be - * looked for in a list of locations to ease the vendoring of a sub-set of - * classes for large projects. - * - * Example usage: - * - * require 'vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php'; - * require 'vendor/symfony/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php'; - * - * use Symfony\Component\ClassLoader\ApcUniversalClassLoader; - * - * $loader = new ApcUniversalClassLoader('apc.prefix.'); - * - * // register classes with namespaces - * $loader->registerNamespaces(array( - * 'Symfony\Component' => __DIR__.'/component', - * 'Symfony' => __DIR__.'/framework', - * 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'), - * )); - * - * // register a library using the PEAR naming convention - * $loader->registerPrefixes(array( - * 'Swift_' => __DIR__.'/Swift', - * )); - * - * // activate the autoloader - * $loader->register(); - * - * In this example, if you try to use a class in the Symfony\Component - * namespace or one of its children (Symfony\Component\Console for instance), - * the autoloader will first look for the class under the component/ - * directory, and it will then fallback to the framework/ directory if not - * found before giving up. - * - * @author Fabien Potencier - * @author Kris Wallsmith - * - * @api - * - * @deprecated since version 2.4, to be removed in 3.0. - * Use the {@link ClassLoader} class instead. - */ -class ApcUniversalClassLoader extends UniversalClassLoader -{ - private $prefix; - - /** - * Constructor. - * - * @param string $prefix A prefix to create a namespace in APC - * - * @throws \RuntimeException - * - * @api - */ - public function __construct($prefix) - { - if (!extension_loaded('apc')) { - throw new \RuntimeException('Unable to use ApcUniversalClassLoader as APC is not enabled.'); - } - - $this->prefix = $prefix; - } - - /** - * Finds a file by class name while caching lookups to APC. - * - * @param string $class A class name to resolve to file - * - * @return string|null The path, if found - */ - public function findFile($class) - { - if (false === $file = apc_fetch($this->prefix.$class)) { - apc_store($this->prefix.$class, $file = parent::findFile($class)); - } - - return $file; - } -} diff --git a/src/Symfony/Component/ClassLoader/CHANGELOG.md b/src/Symfony/Component/ClassLoader/CHANGELOG.md index 64660a8768645..64ef8d9c9bcfa 100644 --- a/src/Symfony/Component/ClassLoader/CHANGELOG.md +++ b/src/Symfony/Component/ClassLoader/CHANGELOG.md @@ -1,6 +1,14 @@ CHANGELOG ========= +3.0.0 +----- + + * The DebugClassLoader class has been removed + * The DebugUniversalClassLoader class has been removed + * The UniversalClassLoader class has been removed + * The ApcUniversalClassLoader class has been removed + 2.4.0 ----- diff --git a/src/Symfony/Component/ClassLoader/DebugClassLoader.php b/src/Symfony/Component/ClassLoader/DebugClassLoader.php deleted file mode 100644 index 473a7bdf4a89b..0000000000000 --- a/src/Symfony/Component/ClassLoader/DebugClassLoader.php +++ /dev/null @@ -1,124 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\ClassLoader; - -trigger_error('The '.__NAMESPACE__.'\DebugClassLoader class is deprecated since version 2.4 and will be removed in 3.0. Use the Symfony\Component\Debug\DebugClassLoader class instead.', E_USER_DEPRECATED); - -/** - * Autoloader checking if the class is really defined in the file found. - * - * The DebugClassLoader will wrap all registered autoloaders providing a - * findFile method and will throw an exception if a file is found but does - * not declare the class. - * - * @author Fabien Potencier - * @author Christophe Coevoet - * - * @api - * - * @deprecated since version 2.4, to be removed in 3.0. - * Use {@link \Symfony\Component\Debug\DebugClassLoader} instead. - */ -class DebugClassLoader -{ - private $classFinder; - - /** - * Constructor. - * - * @param object $classFinder - * - * @api - */ - public function __construct($classFinder) - { - $this->classFinder = $classFinder; - } - - /** - * Gets the wrapped class loader. - * - * @return object a class loader instance - */ - public function getClassLoader() - { - return $this->classFinder; - } - - /** - * Replaces all autoloaders implementing a findFile method by a DebugClassLoader wrapper. - */ - public static function enable() - { - if (!is_array($functions = spl_autoload_functions())) { - return; - } - - foreach ($functions as $function) { - spl_autoload_unregister($function); - } - - foreach ($functions as $function) { - if (is_array($function) && !$function[0] instanceof self && method_exists($function[0], 'findFile')) { - $function = array(new static($function[0]), 'loadClass'); - } - - spl_autoload_register($function); - } - } - - /** - * Unregisters this instance as an autoloader. - */ - public function unregister() - { - spl_autoload_unregister(array($this, 'loadClass')); - } - - /** - * Finds a file by class name. - * - * @param string $class A class name to resolve to file - * - * @return string|null - */ - public function findFile($class) - { - return $this->classFinder->findFile($class); - } - - /** - * Loads the given class or interface. - * - * @param string $class The name of the class - * - * @return bool|null True, if loaded - * - * @throws \RuntimeException - */ - public function loadClass($class) - { - if ($file = $this->classFinder->findFile($class)) { - require $file; - - if (!class_exists($class, false) && !interface_exists($class, false) && !trait_exists($class, false)) { - if (false !== strpos($class, '/')) { - throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/".', $class)); - } - - throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file)); - } - - return true; - } - } -} diff --git a/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php b/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php deleted file mode 100644 index 69005baa274cc..0000000000000 --- a/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\ClassLoader; - -trigger_error('The '.__NAMESPACE__.'\DebugUniversalClassLoader class is deprecated since version 2.4 and will be removed in 3.0. Use the Symfony\Component\Debug\DebugClassLoader class instead.', E_USER_DEPRECATED); - -/** - * Checks that the class is actually declared in the included file. - * - * @author Fabien Potencier - * - * @deprecated since version 2.4, to be removed in 3.0. - * Use the {@link \Symfony\Component\Debug\DebugClassLoader} class instead. - */ -class DebugUniversalClassLoader extends UniversalClassLoader -{ - /** - * Replaces all regular UniversalClassLoader instances by a DebugUniversalClassLoader ones. - */ - public static function enable() - { - if (!is_array($functions = spl_autoload_functions())) { - return; - } - - foreach ($functions as $function) { - spl_autoload_unregister($function); - } - - foreach ($functions as $function) { - if (is_array($function) && $function[0] instanceof UniversalClassLoader) { - $loader = new static(); - $loader->registerNamespaceFallbacks($function[0]->getNamespaceFallbacks()); - $loader->registerPrefixFallbacks($function[0]->getPrefixFallbacks()); - $loader->registerNamespaces($function[0]->getNamespaces()); - $loader->registerPrefixes($function[0]->getPrefixes()); - $loader->useIncludePath($function[0]->getUseIncludePath()); - - $function[0] = $loader; - } - - spl_autoload_register($function); - } - } - - /** - * {@inheritdoc} - */ - public function loadClass($class) - { - if ($file = $this->findFile($class)) { - require $file; - - if (!class_exists($class, false) && !interface_exists($class, false) && !trait_exists($class, false)) { - throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file)); - } - } - } -} diff --git a/src/Symfony/Component/ClassLoader/README.md b/src/Symfony/Component/ClassLoader/README.md index 37df04869961f..18acb356e2861 100644 --- a/src/Symfony/Component/ClassLoader/README.md +++ b/src/Symfony/Component/ClassLoader/README.md @@ -25,8 +25,8 @@ $loader->addPrefix('Symfony', __DIR__.'/src'); $loader->addPrefix('Monolog', __DIR__.'/vendor/monolog/src'); ``` -The `addPrefix()` method takes a namespace prefix and a path where to -look for the classes as arguments. +The `addPrefix()` method takes a namespace prefix and a path where to look for +the classes as arguments. You can also register a sub-namespaces: diff --git a/src/Symfony/Component/ClassLoader/Tests/LegacyApcUniversalClassLoaderTest.php b/src/Symfony/Component/ClassLoader/Tests/ApcClassLoaderTest.php similarity index 69% rename from src/Symfony/Component/ClassLoader/Tests/LegacyApcUniversalClassLoaderTest.php rename to src/Symfony/Component/ClassLoader/Tests/ApcClassLoaderTest.php index 8a1f203118e65..1f6d15076996a 100644 --- a/src/Symfony/Component/ClassLoader/Tests/LegacyApcUniversalClassLoaderTest.php +++ b/src/Symfony/Component/ClassLoader/Tests/ApcClassLoaderTest.php @@ -11,14 +11,13 @@ namespace Symfony\Component\ClassLoader\Tests; -use Symfony\Component\ClassLoader\ApcUniversalClassLoader; +use Symfony\Component\ClassLoader\ApcClassLoader; +use Symfony\Component\ClassLoader\ClassLoader; -class LegacyApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase +class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase { protected function setUp() { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - if (!extension_loaded('apc')) { $this->markTestSkipped('The apc extension is not available.'); } @@ -39,45 +38,51 @@ protected function tearDown() public function testConstructor() { - $loader = new ApcUniversalClassLoader('test.prefix.'); - $loader->registerNamespace('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); + $loader = new ClassLoader(); + $loader->addPrefix('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); + + $loader = new ApcClassLoader('test.prefix.', $loader); $this->assertEquals($loader->findFile('\Apc\Namespaced\FooBar'), apc_fetch('test.prefix.\Apc\Namespaced\FooBar'), '__construct() takes a prefix as its first argument'); } - /** - * @dataProvider getLoadClassTests - */ - public function testLoadClass($className, $testClassName, $message) - { - $loader = new ApcUniversalClassLoader('test.prefix.'); - $loader->registerNamespace('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerPrefix('Apc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->loadClass($testClassName); - $this->assertTrue(class_exists($className), $message); - } + /** + * @dataProvider getLoadClassTests + */ + public function testLoadClass($className, $testClassName, $message) + { + $loader = new ClassLoader(); + $loader->addPrefix('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); + $loader->addPrefix('Apc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); + + $loader = new ApcClassLoader('test.prefix.', $loader); + $loader->loadClass($testClassName); + $this->assertTrue(class_exists($className), $message); + } public function getLoadClassTests() { return array( array('\\Apc\\Namespaced\\Foo', 'Apc\\Namespaced\\Foo', '->loadClass() loads Apc\Namespaced\Foo class'), array('Apc_Pearlike_Foo', 'Apc_Pearlike_Foo', '->loadClass() loads Apc_Pearlike_Foo class'), - ); + ); } - /** - * @dataProvider getLoadClassFromFallbackTests - */ - public function testLoadClassFromFallback($className, $testClassName, $message) - { - $loader = new ApcUniversalClassLoader('test.prefix.fallback'); - $loader->registerNamespace('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerPrefix('Apc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerNamespaceFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/fallback')); - $loader->registerPrefixFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/fallback')); - $loader->loadClass($testClassName); - $this->assertTrue(class_exists($className), $message); - } + /** + * @dataProvider getLoadClassFromFallbackTests + */ + public function testLoadClassFromFallback($className, $testClassName, $message) + { + $loader = new ClassLoader(); + $loader->addPrefix('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); + $loader->addPrefix('Apc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); + $loader->addPrefix('', array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/fallback')); + + $loader = new ApcClassLoader('test.prefix.fallback', $loader); + $loader->loadClass($testClassName); + + $this->assertTrue(class_exists($className), $message); + } public function getLoadClassFromFallbackTests() { @@ -89,18 +94,19 @@ public function getLoadClassFromFallbackTests() ); } - /** - * @dataProvider getLoadClassNamespaceCollisionTests - */ - public function testLoadClassNamespaceCollision($namespaces, $className, $message) - { - $loader = new ApcUniversalClassLoader('test.prefix.collision.'); - $loader->registerNamespaces($namespaces); + /** + * @dataProvider getLoadClassNamespaceCollisionTests + */ + public function testLoadClassNamespaceCollision($namespaces, $className, $message) + { + $loader = new ClassLoader(); + $loader->addPrefixes($namespaces); - $loader->loadClass($className); + $loader = new ApcClassLoader('test.prefix.collision.', $loader); + $loader->loadClass($className); - $this->assertTrue(class_exists($className), $message); - } + $this->assertTrue(class_exists($className), $message); + } public function getLoadClassNamespaceCollisionTests() { @@ -137,20 +143,22 @@ public function getLoadClassNamespaceCollisionTests() 'Apc\NamespaceCollision\A\B\Bar', '->loadClass() loads NamespaceCollision\A\B\Bar from beta.', ), - ); + ); } - /** - * @dataProvider getLoadClassPrefixCollisionTests - */ - public function testLoadClassPrefixCollision($prefixes, $className, $message) - { - $loader = new ApcUniversalClassLoader('test.prefix.collision.'); - $loader->registerPrefixes($prefixes); + /** + * @dataProvider getLoadClassPrefixCollisionTests + */ + public function testLoadClassPrefixCollision($prefixes, $className, $message) + { + $loader = new ClassLoader(); + $loader->addPrefixes($prefixes); + + $loader = new ApcClassLoader('test.prefix.collision.', $loader); + $loader->loadClass($className); - $loader->loadClass($className); - $this->assertTrue(class_exists($className), $message); - } + $this->assertTrue(class_exists($className), $message); + } public function getLoadClassPrefixCollisionTests() { @@ -187,6 +195,6 @@ public function getLoadClassPrefixCollisionTests() 'ApcPrefixCollision_A_B_Bar', '->loadClass() loads ApcPrefixCollision_A_B_Bar from beta.', ), - ); + ); } } diff --git a/src/Symfony/Component/ClassLoader/Tests/LegacyUniversalClassLoaderTest.php b/src/Symfony/Component/ClassLoader/Tests/LegacyUniversalClassLoaderTest.php deleted file mode 100644 index f654f792fb296..0000000000000 --- a/src/Symfony/Component/ClassLoader/Tests/LegacyUniversalClassLoaderTest.php +++ /dev/null @@ -1,225 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\ClassLoader\Tests; - -use Symfony\Component\ClassLoader\UniversalClassLoader; - -class LegacyUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - } - - /** - * @dataProvider getLoadClassTests - */ - public function testLoadClass($className, $testClassName, $message) - { - $loader = new UniversalClassLoader(); - $loader->registerNamespace('Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerPrefix('Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $this->assertTrue($loader->loadClass($testClassName)); - $this->assertTrue(class_exists($className), $message); - } - - public function getLoadClassTests() - { - return array( - array('\\Namespaced\\Foo', 'Namespaced\\Foo', '->loadClass() loads Namespaced\Foo class'), - array('\\Pearlike_Foo', 'Pearlike_Foo', '->loadClass() loads Pearlike_Foo class'), - ); - } - - public function testUseIncludePath() - { - $loader = new UniversalClassLoader(); - $this->assertFalse($loader->getUseIncludePath()); - - $this->assertNull($loader->findFile('Foo')); - - $includePath = get_include_path(); - - $loader->useIncludePath(true); - $this->assertTrue($loader->getUseIncludePath()); - - set_include_path(__DIR__.'/Fixtures/includepath'.PATH_SEPARATOR.$includePath); - - $this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'includepath'.DIRECTORY_SEPARATOR.'Foo.php', $loader->findFile('Foo')); - - set_include_path($includePath); - } - - public function testGetNamespaces() - { - $loader = new UniversalClassLoader(); - $loader->registerNamespace('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerNamespace('Bar', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerNamespace('Bas', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $namespaces = $loader->getNamespaces(); - $this->assertArrayHasKey('Foo', $namespaces); - $this->assertArrayNotHasKey('Foo1', $namespaces); - $this->assertArrayHasKey('Bar', $namespaces); - $this->assertArrayHasKey('Bas', $namespaces); - } - - public function testGetPrefixes() - { - $loader = new UniversalClassLoader(); - $loader->registerPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerPrefix('Bar', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerPrefix('Bas', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $prefixes = $loader->getPrefixes(); - $this->assertArrayHasKey('Foo', $prefixes); - $this->assertArrayNotHasKey('Foo1', $prefixes); - $this->assertArrayHasKey('Bar', $prefixes); - $this->assertArrayHasKey('Bas', $prefixes); - } - - /** - * @dataProvider getLoadClassFromFallbackTests - */ - public function testLoadClassFromFallback($className, $testClassName, $message) - { - $loader = new UniversalClassLoader(); - $loader->registerNamespace('Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerPrefix('Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); - $loader->registerNamespaceFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback')); - $loader->registerPrefixFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback')); - $this->assertTrue($loader->loadClass($testClassName)); - $this->assertTrue(class_exists($className), $message); - } - - public function getLoadClassFromFallbackTests() - { - return array( - array('\\Namespaced\\Baz', 'Namespaced\\Baz', '->loadClass() loads Namespaced\Baz class'), - array('\\Pearlike_Baz', 'Pearlike_Baz', '->loadClass() loads Pearlike_Baz class'), - array('\\Namespaced\\FooBar', 'Namespaced\\FooBar', '->loadClass() loads Namespaced\Baz class from fallback dir'), - array('\\Pearlike_FooBar', 'Pearlike_FooBar', '->loadClass() loads Pearlike_Baz class from fallback dir'), - ); - } - - 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 - */ - public function testLoadClassNamespaceCollision($namespaces, $className, $message) - { - $loader = new UniversalClassLoader(); - $loader->registerNamespaces($namespaces); - - $this->assertTrue($loader->loadClass($className)); - $this->assertTrue(class_exists($className), $message); - } - - public function getLoadClassNamespaceCollisionTests() - { - return array( - array( - array( - 'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha', - 'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta', - ), - 'NamespaceCollision\A\Foo', - '->loadClass() loads NamespaceCollision\A\Foo from alpha.', - ), - array( - array( - 'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta', - 'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha', - ), - 'NamespaceCollision\A\Bar', - '->loadClass() loads NamespaceCollision\A\Bar from alpha.', - ), - array( - array( - 'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha', - 'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta', - ), - 'NamespaceCollision\A\B\Foo', - '->loadClass() loads NamespaceCollision\A\B\Foo from beta.', - ), - array( - array( - 'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta', - 'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha', - ), - 'NamespaceCollision\A\B\Bar', - '->loadClass() loads NamespaceCollision\A\B\Bar from beta.', - ), - ); - } - - /** - * @dataProvider getLoadClassPrefixCollisionTests - */ - public function testLoadClassPrefixCollision($prefixes, $className, $message) - { - $loader = new UniversalClassLoader(); - $loader->registerPrefixes($prefixes); - - $this->assertTrue($loader->loadClass($className)); - $this->assertTrue(class_exists($className), $message); - } - - public function getLoadClassPrefixCollisionTests() - { - return array( - array( - array( - 'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha', - 'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta', - ), - 'PrefixCollision_A_Foo', - '->loadClass() loads PrefixCollision_A_Foo from alpha.', - ), - array( - array( - 'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta', - 'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha', - ), - 'PrefixCollision_A_Bar', - '->loadClass() loads PrefixCollision_A_Bar from alpha.', - ), - array( - array( - 'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha', - 'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta', - ), - 'PrefixCollision_A_B_Foo', - '->loadClass() loads PrefixCollision_A_B_Foo from beta.', - ), - array( - array( - 'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta', - 'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha', - ), - 'PrefixCollision_A_B_Bar', - '->loadClass() loads PrefixCollision_A_B_Bar from beta.', - ), - ); - } -} diff --git a/src/Symfony/Component/ClassLoader/UniversalClassLoader.php b/src/Symfony/Component/ClassLoader/UniversalClassLoader.php deleted file mode 100644 index 781d3a29a931b..0000000000000 --- a/src/Symfony/Component/ClassLoader/UniversalClassLoader.php +++ /dev/null @@ -1,323 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\ClassLoader; - -trigger_error('The '.__NAMESPACE__.'\UniversalClassLoader class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Component\ClassLoader\ClassLoader class instead.', E_USER_DEPRECATED); - -/** - * UniversalClassLoader implements a "universal" autoloader for PHP 5.3. - * - * It is able to load classes that use either: - * - * * The technical interoperability standards for PHP 5.3 namespaces and - * class names (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md); - * - * * The PEAR naming convention for classes (http://pear.php.net/). - * - * Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be - * looked for in a list of locations to ease the vendoring of a sub-set of - * classes for large projects. - * - * Example usage: - * - * $loader = new UniversalClassLoader(); - * - * // register classes with namespaces - * $loader->registerNamespaces(array( - * 'Symfony\Component' => __DIR__.'/component', - * 'Symfony' => __DIR__.'/framework', - * 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'), - * )); - * - * // register a library using the PEAR naming convention - * $loader->registerPrefixes(array( - * 'Swift_' => __DIR__.'/Swift', - * )); - * - * - * // to enable searching the include path (e.g. for PEAR packages) - * $loader->useIncludePath(true); - * - * // activate the autoloader - * $loader->register(); - * - * In this example, if you try to use a class in the Symfony\Component - * namespace or one of its children (Symfony\Component\Console for instance), - * the autoloader will first look for the class under the component/ - * directory, and it will then fallback to the framework/ directory if not - * found before giving up. - * - * @author Fabien Potencier - * - * @api - * - * @deprecated since version 2.4, to be removed in 3.0. - * Use the {@link ClassLoader} class instead. - */ -class UniversalClassLoader -{ - private $namespaces = array(); - private $prefixes = array(); - private $namespaceFallbacks = array(); - private $prefixFallbacks = array(); - private $useIncludePath = false; - - /** - * Turns on searching the include for class files. Allows easy loading - * of installed PEAR packages. - * - * @param bool $useIncludePath - */ - public function useIncludePath($useIncludePath) - { - $this->useIncludePath = (bool) $useIncludePath; - } - - /** - * Can be used to check if the autoloader uses the include path to check - * for classes. - * - * @return bool - */ - public function getUseIncludePath() - { - return $this->useIncludePath; - } - - /** - * Gets the configured namespaces. - * - * @return array A hash with namespaces as keys and directories as values - */ - public function getNamespaces() - { - return $this->namespaces; - } - - /** - * Gets the configured class prefixes. - * - * @return array A hash with class prefixes as keys and directories as values - */ - public function getPrefixes() - { - return $this->prefixes; - } - - /** - * Gets the directory(ies) to use as a fallback for namespaces. - * - * @return array An array of directories - */ - public function getNamespaceFallbacks() - { - return $this->namespaceFallbacks; - } - - /** - * Gets the directory(ies) to use as a fallback for class prefixes. - * - * @return array An array of directories - */ - public function getPrefixFallbacks() - { - return $this->prefixFallbacks; - } - - /** - * Registers the directory to use as a fallback for namespaces. - * - * @param array $dirs An array of directories - * - * @api - */ - public function registerNamespaceFallbacks(array $dirs) - { - $this->namespaceFallbacks = $dirs; - } - - /** - * 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 - * - * @api - */ - 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. - * - * @param array $namespaces An array of namespaces (namespaces as keys and locations as values) - * - * @api - */ - public function registerNamespaces(array $namespaces) - { - foreach ($namespaces as $namespace => $locations) { - $this->namespaces[$namespace] = (array) $locations; - } - } - - /** - * Registers a namespace. - * - * @param string $namespace The namespace - * @param array|string $paths The location(s) of the namespace - * - * @api - */ - public function registerNamespace($namespace, $paths) - { - $this->namespaces[$namespace] = (array) $paths; - } - - /** - * Registers an array of classes using the PEAR naming convention. - * - * @param array $classes An array of classes (prefixes as keys and locations as values) - * - * @api - */ - public function registerPrefixes(array $classes) - { - foreach ($classes as $prefix => $locations) { - $this->prefixes[$prefix] = (array) $locations; - } - } - - /** - * Registers a set of classes using the PEAR naming convention. - * - * @param string $prefix The classes prefix - * @param array|string $paths The location(s) of the classes - * - * @api - */ - public function registerPrefix($prefix, $paths) - { - $this->prefixes[$prefix] = (array) $paths; - } - - /** - * Registers this instance as an autoloader. - * - * @param bool $prepend Whether to prepend the autoloader or not - * - * @api - */ - public function register($prepend = false) - { - spl_autoload_register(array($this, 'loadClass'), true, $prepend); - } - - /** - * Loads the given class or interface. - * - * @param string $class The name of the class - * - * @return bool|null True, if loaded - */ - public function loadClass($class) - { - if ($file = $this->findFile($class)) { - require $file; - - return true; - } - } - - /** - * Finds the path to the file where the class is defined. - * - * @param string $class The name of the class - * - * @return string|null The path, if found - */ - public function findFile($class) - { - if (false !== $pos = strrpos($class, '\\')) { - // namespaced class name - $namespace = substr($class, 0, $pos); - $className = substr($class, $pos + 1); - $normalizedClass = str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php'; - foreach ($this->namespaces as $ns => $dirs) { - if (0 !== strpos($namespace, $ns)) { - continue; - } - - foreach ($dirs as $dir) { - $file = $dir.DIRECTORY_SEPARATOR.$normalizedClass; - if (is_file($file)) { - return $file; - } - } - } - - foreach ($this->namespaceFallbacks as $dir) { - $file = $dir.DIRECTORY_SEPARATOR.$normalizedClass; - if (is_file($file)) { - return $file; - } - } - } else { - // PEAR-like class name - $normalizedClass = str_replace('_', DIRECTORY_SEPARATOR, $class).'.php'; - foreach ($this->prefixes as $prefix => $dirs) { - if (0 !== strpos($class, $prefix)) { - continue; - } - - foreach ($dirs as $dir) { - $file = $dir.DIRECTORY_SEPARATOR.$normalizedClass; - if (is_file($file)) { - return $file; - } - } - } - - foreach ($this->prefixFallbacks as $dir) { - $file = $dir.DIRECTORY_SEPARATOR.$normalizedClass; - if (is_file($file)) { - return $file; - } - } - } - - if ($this->useIncludePath && $file = stream_resolve_include_path($normalizedClass)) { - return $file; - } - } -} diff --git a/src/Symfony/Component/ClassLoader/WinCacheClassLoader.php b/src/Symfony/Component/ClassLoader/WinCacheClassLoader.php index 0fc11d019f862..7ba0d9df582f4 100644 --- a/src/Symfony/Component/ClassLoader/WinCacheClassLoader.php +++ b/src/Symfony/Component/ClassLoader/WinCacheClassLoader.php @@ -16,12 +16,10 @@ * * It expects an object implementing a findFile method to find the file. This * allow using it as a wrapper around the other loaders of the component (the - * ClassLoader and the UniversalClassLoader for instance) but also around any - * other autoloaders following this convention (the Composer one for instance). + * ClassLoader for instance) but also around any other autoloaders following + * this convention (the Composer one for instance). * * // with a Symfony autoloader - * use Symfony\Component\ClassLoader\ClassLoader; - * * $loader = new ClassLoader(); * $loader->addPrefix('Symfony\Component', __DIR__.'/component'); * $loader->addPrefix('Symfony', __DIR__.'/framework'); diff --git a/src/Symfony/Component/ClassLoader/XcacheClassLoader.php b/src/Symfony/Component/ClassLoader/XcacheClassLoader.php index 19c130349a95f..f688ce772735b 100644 --- a/src/Symfony/Component/ClassLoader/XcacheClassLoader.php +++ b/src/Symfony/Component/ClassLoader/XcacheClassLoader.php @@ -16,12 +16,10 @@ * * It expects an object implementing a findFile method to find the file. This * allows using it as a wrapper around the other loaders of the component (the - * ClassLoader and the UniversalClassLoader for instance) but also around any - * other autoloaders following this convention (the Composer one for instance). + * ClassLoader for instance) but also around any other autoloaders following + * this convention (the Composer one for instance). * * // with a Symfony autoloader - * use Symfony\Component\ClassLoader\ClassLoader; - * * $loader = new ClassLoader(); * $loader->addPrefix('Symfony\Component', __DIR__.'/component'); * $loader->addPrefix('Symfony', __DIR__.'/framework'); diff --git a/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php b/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php index 571a980c2fda8..be5772bef19fb 100644 --- a/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php +++ b/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php @@ -16,7 +16,6 @@ use Symfony\Component\Debug\DebugClassLoader; use Composer\Autoload\ClassLoader as ComposerClassLoader; use Symfony\Component\ClassLoader\ClassLoader as SymfonyClassLoader; -use Symfony\Component\ClassLoader\UniversalClassLoader as SymfonyUniversalClassLoader; /** * ErrorHandler for classes that do not exist. @@ -111,7 +110,7 @@ private function getClassCandidates($class) } } - if ($function[0] instanceof ComposerClassLoader || $function[0] instanceof SymfonyClassLoader || $function[0] instanceof SymfonyUniversalClassLoader) { + if ($function[0] instanceof ComposerClassLoader || $function[0] instanceof SymfonyClassLoader) { foreach ($function[0]->getPrefixes() as $prefix => $paths) { foreach ($paths as $path) { $classes = array_merge($classes, $this->findClassInPath($path, $class, $prefix)); diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php index 1ae6fc4f648ff..689fe08b621ad 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Debug\Tests\FatalErrorHandler; use Symfony\Component\ClassLoader\ClassLoader as SymfonyClassLoader; -use Symfony\Component\ClassLoader\UniversalClassLoader as SymfonyUniversalClassLoader; use Symfony\Component\Debug\Exception\FatalErrorException; use Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler; @@ -119,9 +118,6 @@ public function provideLegacyClassNotFoundData() $symfonyAutoloader = new SymfonyClassLoader(); $symfonyAutoloader->addPrefixes($prefixes); - $symfonyUniversalClassLoader = new SymfonyUniversalClassLoader(); - $symfonyUniversalClassLoader->registerPrefixes($prefixes); - return array( array( array( @@ -133,16 +129,6 @@ public function provideLegacyClassNotFoundData() "Attempted to load class \"UndefinedFunctionException\" from namespace \"Foo\Bar\".\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?", array($symfonyAutoloader, 'loadClass'), ), - array( - array( - 'type' => 1, - 'line' => 12, - 'file' => 'foo.php', - 'message' => 'Class \'Foo\\Bar\\UndefinedFunctionException\' not found', - ), - "Attempted to load class \"UndefinedFunctionException\" from namespace \"Foo\Bar\".\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?", - array($symfonyUniversalClassLoader, 'loadClass'), - ), array( array( 'type' => 1,