mirror of
https://github.com/symfony/class-loader.git
synced 2026-03-24 17:22:11 +01:00
Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
598dfd4610 | ||
|
|
85b2532f2f | ||
|
|
1ecb64f0c2 | ||
|
|
cc6272033e | ||
|
|
41f582851c | ||
|
|
e722b63c50 | ||
|
|
ad6b79e597 | ||
|
|
b44bb69fd2 | ||
|
|
731d5a42fa | ||
|
|
34e525229a | ||
|
|
d7819f2f17 | ||
|
|
2f8a6f96e2 | ||
|
|
53074e1533 | ||
|
|
35e977baae | ||
|
|
e2a07cb502 | ||
|
|
307598c291 | ||
|
|
8defca3a59 | ||
|
|
47b66544f8 | ||
|
|
a57eb271c2 | ||
|
|
4993c270bb | ||
|
|
0d2d67d18f | ||
|
|
ea9e58e776 | ||
|
|
09a40f5433 | ||
|
|
46754025d0 | ||
|
|
6b87e5db15 | ||
|
|
39a9bc391d | ||
|
|
d3b0938fa2 | ||
|
|
3acea26b17 | ||
|
|
732b31a9fe | ||
|
|
afb83252cb | ||
|
|
b321e4830b | ||
|
|
343414e2a5 | ||
|
|
e971e40b45 | ||
|
|
dd8c297b91 | ||
|
|
26de2f175f | ||
|
|
142de518bf | ||
|
|
8a70d1963f | ||
|
|
18d1b5e575 |
@@ -15,13 +15,21 @@ namespace Symfony\Component\ClassLoader;
|
||||
* ApcClassLoader implements a wrapping autoloader cached in APC for PHP 5.3.
|
||||
*
|
||||
* 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
|
||||
* 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 autoloader following this convention (the Composer one for instance)
|
||||
* 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');
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* // or with a Composer autoloader
|
||||
* use Composer\Autoload\ClassLoader;
|
||||
*
|
||||
* $loader = new ClassLoader();
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
@@ -44,18 +52,17 @@ class ApcClassLoader
|
||||
private $prefix;
|
||||
|
||||
/**
|
||||
* The class loader object being decorated.
|
||||
* A class loader object that implements the findFile() method.
|
||||
*
|
||||
* @var \Symfony\Component\ClassLoader\ClassLoader
|
||||
* A class loader object that implements the findFile() method.
|
||||
* @var object
|
||||
*/
|
||||
protected $decorated;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $prefix The APC namespace prefix to use.
|
||||
* @param object $decorated A class loader object that implements the findFile() method.
|
||||
* @param string $prefix The APC namespace prefix to use.
|
||||
* @param object $decorated A class loader object that implements the findFile() method.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @throws \InvalidArgumentException
|
||||
@@ -79,7 +86,7 @@ class ApcClassLoader
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param Boolean $prepend Whether to prepend the autoloader or not
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
@@ -99,7 +106,7 @@ class ApcClassLoader
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return Boolean|null True, if loaded
|
||||
* @return bool|null True, if loaded
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
@@ -133,5 +140,4 @@ class ApcClassLoader
|
||||
{
|
||||
return call_user_func_array(array($this->decorated, $method), $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ namespace Symfony\Component\ClassLoader;
|
||||
* // register classes with namespaces
|
||||
* $loader->registerNamespaces(array(
|
||||
* 'Symfony\Component' => __DIR__.'/component',
|
||||
* 'Symfony' => __DIR__.'/framework',
|
||||
* 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
|
||||
* 'Symfony' => __DIR__.'/framework',
|
||||
* 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
|
||||
* ));
|
||||
*
|
||||
* // register a library using the PEAR naming convention
|
||||
|
||||
@@ -25,12 +25,12 @@ class ClassCollectionLoader
|
||||
/**
|
||||
* Loads a list of classes and caches them in one big file.
|
||||
*
|
||||
* @param array $classes An array of classes to load
|
||||
* @param string $cacheDir A cache directory
|
||||
* @param string $name The cache name prefix
|
||||
* @param Boolean $autoReload Whether to flush the cache when the cache is stale or not
|
||||
* @param Boolean $adaptive Whether to remove already declared classes or not
|
||||
* @param string $extension File extension of the resulting file
|
||||
* @param array $classes An array of classes to load
|
||||
* @param string $cacheDir A cache directory
|
||||
* @param string $name The cache name prefix
|
||||
* @param bool $autoReload Whether to flush the cache when the cache is stale or not
|
||||
* @param bool $adaptive Whether to remove already declared classes or not
|
||||
* @param string $extension File extension of the resulting file
|
||||
*
|
||||
* @throws \InvalidArgumentException When class can't be loaded
|
||||
*/
|
||||
@@ -200,7 +200,7 @@ class ClassCollectionLoader
|
||||
*/
|
||||
public static function enableTokenizer($bool)
|
||||
{
|
||||
self::$useTokenizer = (Boolean) $bool;
|
||||
self::$useTokenizer = (bool) $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,10 +335,10 @@ class ClassCollectionLoader
|
||||
* This function does not check for circular dependencies as it should never
|
||||
* occur with PHP traits.
|
||||
*
|
||||
* @param array $tree The dependency tree
|
||||
* @param \ReflectionClass $node The node
|
||||
* @param \ArrayObject $resolved An array of already resolved dependencies
|
||||
* @param \ArrayObject $unresolved An array of dependencies to be resolved
|
||||
* @param array $tree The dependency tree
|
||||
* @param \ReflectionClass $node The node
|
||||
* @param \ArrayObject $resolved An array of already resolved dependencies
|
||||
* @param \ArrayObject $unresolved An array of dependencies to be resolved
|
||||
*
|
||||
* @return \ArrayObject The dependencies for the given node
|
||||
*
|
||||
@@ -353,14 +353,17 @@ class ClassCollectionLoader
|
||||
$unresolved = new \ArrayObject();
|
||||
}
|
||||
$nodeName = $node->getName();
|
||||
$unresolved[$nodeName] = $node;
|
||||
foreach ($tree[$nodeName] as $dependency) {
|
||||
if (!$resolved->offsetExists($dependency->getName())) {
|
||||
self::resolveDependencies($tree, $dependency, $resolved, $unresolved);
|
||||
|
||||
if (isset($tree[$nodeName])) {
|
||||
$unresolved[$nodeName] = $node;
|
||||
foreach ($tree[$nodeName] as $dependency) {
|
||||
if (!$resolved->offsetExists($dependency->getName())) {
|
||||
self::resolveDependencies($tree, $dependency, $resolved, $unresolved);
|
||||
}
|
||||
}
|
||||
$resolved[$nodeName] = $node;
|
||||
unset($unresolved[$nodeName]);
|
||||
}
|
||||
$resolved[$nodeName] = $node;
|
||||
unset($unresolved[$nodeName]);
|
||||
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
/**
|
||||
* ClassLoader implements an PSR-0 class loader
|
||||
* ClassLoader implements an PSR-0 class loader.
|
||||
*
|
||||
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
|
||||
*
|
||||
@@ -76,7 +76,7 @@ class ClassLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of classes
|
||||
* Registers a set of classes.
|
||||
*
|
||||
* @param string $prefix The classes prefix
|
||||
* @param array|string $paths The location(s) of the classes
|
||||
@@ -103,18 +103,18 @@ class ClassLoader
|
||||
/**
|
||||
* Turns on searching the include for class files.
|
||||
*
|
||||
* @param Boolean $useIncludePath
|
||||
* @param bool $useIncludePath
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
$this->useIncludePath = (bool) $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return Boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
@@ -124,7 +124,7 @@ class ClassLoader
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param Boolean $prepend Whether to prepend the autoloader or not
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
@@ -144,7 +144,7 @@ class ClassLoader
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return Boolean|null True, if loaded
|
||||
* @return bool|null True, if loaded
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
|
||||
@@ -11,15 +11,23 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
if (!defined('SYMFONY_TRAIT')) {
|
||||
if (PHP_VERSION_ID >= 50400) {
|
||||
define('SYMFONY_TRAIT', T_TRAIT);
|
||||
} else {
|
||||
define('SYMFONY_TRAIT', 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ClassMapGenerator
|
||||
* ClassMapGenerator.
|
||||
*
|
||||
* @author Gyula Sallai <salla016@gmail.com>
|
||||
*/
|
||||
class ClassMapGenerator
|
||||
{
|
||||
/**
|
||||
* Generate a class map file
|
||||
* Generate a class map file.
|
||||
*
|
||||
* @param array|string $dirs Directories or a single path to search in
|
||||
* @param string $file The name of the class map file
|
||||
@@ -37,7 +45,7 @@ class ClassMapGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all files in the given directory searching for classes
|
||||
* Iterate over all files in the given directory searching for classes.
|
||||
*
|
||||
* @param \Iterator|string $dir The directory to search in or an iterator
|
||||
*
|
||||
@@ -67,14 +75,13 @@ class ClassMapGenerator
|
||||
foreach ($classes as $class) {
|
||||
$map[$class] = $path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the classes in the given file
|
||||
* Extract the classes in the given file.
|
||||
*
|
||||
* @param string $path The file to check
|
||||
*
|
||||
@@ -83,13 +90,12 @@ class ClassMapGenerator
|
||||
private static function findClasses($path)
|
||||
{
|
||||
$contents = file_get_contents($path);
|
||||
$tokens = token_get_all($contents);
|
||||
$T_TRAIT = version_compare(PHP_VERSION, '5.4', '<') ? -1 : T_TRAIT;
|
||||
$tokens = token_get_all($contents);
|
||||
|
||||
$classes = array();
|
||||
|
||||
$namespace = '';
|
||||
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
|
||||
for ($i = 0, $max = count($tokens); $i < $max; ++$i) {
|
||||
$token = $tokens[$i];
|
||||
|
||||
if (is_string($token)) {
|
||||
@@ -111,7 +117,7 @@ class ClassMapGenerator
|
||||
break;
|
||||
case T_CLASS:
|
||||
case T_INTERFACE:
|
||||
case $T_TRAIT:
|
||||
case SYMFONY_TRAIT:
|
||||
// Find the classname
|
||||
while (($t = $tokens[++$i]) && is_array($t)) {
|
||||
if (T_STRING === $t[0]) {
|
||||
|
||||
@@ -70,7 +70,7 @@ class DebugClassLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a file by class name
|
||||
* Finds a file by class name.
|
||||
*
|
||||
* @param string $class A class name to resolve to file
|
||||
*
|
||||
@@ -86,7 +86,7 @@ class DebugClassLoader
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return Boolean|null True, if loaded
|
||||
* @return bool|null True, if loaded
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
|
||||
@@ -48,7 +48,7 @@ class DebugUniversalClassLoader extends UniversalClassLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2004-2013 Fabien Potencier
|
||||
Copyright (c) 2004-2015 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -33,7 +33,7 @@ class MapClassLoader
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param Boolean $prepend Whether to prepend the autoloader or not
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
|
||||
66
README.md
66
README.md
@@ -4,56 +4,72 @@ ClassLoader Component
|
||||
ClassLoader loads your project classes automatically if they follow some
|
||||
standard PHP conventions.
|
||||
|
||||
The Universal ClassLoader is able to autoload classes that implement the PSR-0
|
||||
The ClassLoader object is able to autoload classes that implement the PSR-0
|
||||
standard or the PEAR naming convention.
|
||||
|
||||
First, register the autoloader:
|
||||
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
```php
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
|
||||
|
||||
use Symfony\Component\ClassLoader\UniversalClassLoader;
|
||||
use Symfony\Component\ClassLoader\ClassLoader;
|
||||
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->register();
|
||||
$loader = new ClassLoader();
|
||||
$loader->register();
|
||||
```
|
||||
|
||||
Then, register some namespaces with the `registerNamespace()` method:
|
||||
Then, register some namespaces with the `addPrefix()` method:
|
||||
|
||||
$loader->registerNamespace('Symfony', __DIR__.'/src');
|
||||
$loader->registerNamespace('Monolog', __DIR__.'/vendor/monolog/src');
|
||||
```php
|
||||
$loader->addPrefix('Symfony', __DIR__.'/src');
|
||||
$loader->addPrefix('Monolog', __DIR__.'/vendor/monolog/src');
|
||||
```
|
||||
|
||||
The `registerNamespace()` method takes a namespace prefix and a path where to
|
||||
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:
|
||||
|
||||
$loader->registerNamespace('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');
|
||||
```php
|
||||
$loader->addPrefix('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');
|
||||
```
|
||||
|
||||
The order of registration is significant and the first registered namespace
|
||||
takes precedence over later registered one.
|
||||
|
||||
You can also register more than one path for a given namespace:
|
||||
|
||||
$loader->registerNamespace('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
|
||||
```php
|
||||
$loader->addPrefix('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
|
||||
```
|
||||
|
||||
Alternatively, you can use the `registerNamespaces()` method to register more
|
||||
Alternatively, you can use the `addPrefixes()` method to register more
|
||||
than one namespace at once:
|
||||
|
||||
$loader->registerNamespaces(array(
|
||||
'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
|
||||
'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
|
||||
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
|
||||
'Monolog' => __DIR__.'/vendor/monolog/src',
|
||||
));
|
||||
```php
|
||||
$loader->addPrefixes(array(
|
||||
'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
|
||||
'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
|
||||
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
|
||||
'Monolog' => __DIR__.'/vendor/monolog/src',
|
||||
));
|
||||
```
|
||||
|
||||
For better performance, you can use the APC based version of the universal
|
||||
class loader:
|
||||
For better performance, you can use the APC class loader:
|
||||
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
|
||||
```php
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcClassLoader.php';
|
||||
|
||||
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
|
||||
use Symfony\Component\ClassLoader\ClassLoader;
|
||||
use Symfony\Component\ClassLoader\ApcClassLoader;
|
||||
|
||||
$loader = new ApcUniversalClassLoader('apc.prefix.');
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Symfony', __DIR__.'/src');
|
||||
|
||||
$loader = new ApcClassLoader('apc.prefix.', $loader);
|
||||
$loader->register();
|
||||
```
|
||||
|
||||
Furthermore, the component provides tools to aggregate classes into a single
|
||||
file, which is especially useful to improve performance on servers that do not
|
||||
@@ -65,5 +81,5 @@ Resources
|
||||
You can run the unit tests with the following command:
|
||||
|
||||
$ cd path/to/Symfony/Component/ClassLoader/
|
||||
$ composer.phar install
|
||||
$ composer install
|
||||
$ phpunit
|
||||
|
||||
@@ -55,15 +55,13 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Apc\\Namespaced\\Foo', '\\Apc\\Namespaced\\Foo', '->loadClass() loads Apc\Namespaced\Foo class'),
|
||||
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'),
|
||||
array('\\Apc\\Namespaced\\Bar', '\\Apc\\Namespaced\\Bar', '->loadClass() loads Apc\Namespaced\Bar class with a leading slash'),
|
||||
array('Apc_Pearlike_Bar', '\\Apc_Pearlike_Bar', '->loadClass() loads Apc_Pearlike_Bar class with a leading slash'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassFromFallbackTests
|
||||
@@ -79,15 +77,15 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassFromFallbackTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Apc\\Namespaced\\Baz', '\\Apc\\Namespaced\\Baz', '->loadClass() loads Apc\Namespaced\Baz class'),
|
||||
public function getLoadClassFromFallbackTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Apc\\Namespaced\\Baz', 'Apc\\Namespaced\\Baz', '->loadClass() loads Apc\Namespaced\Baz class'),
|
||||
array('Apc_Pearlike_Baz', 'Apc_Pearlike_Baz', '->loadClass() loads Apc_Pearlike_Baz class'),
|
||||
array('\\Apc\\Namespaced\\FooBar', '\\Apc\\Namespaced\\FooBar', '->loadClass() loads Apc\Namespaced\Baz class from fallback dir'),
|
||||
array('\\Apc\\Namespaced\\FooBar', 'Apc\\Namespaced\\FooBar', '->loadClass() loads Apc\Namespaced\Baz class from fallback dir'),
|
||||
array('Apc_Pearlike_FooBar', 'Apc_Pearlike_FooBar', '->loadClass() loads Apc_Pearlike_Baz class from fallback dir'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassNamespaceCollisionTests
|
||||
@@ -102,15 +100,15 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassNamespaceCollisionTests()
|
||||
{
|
||||
return array(
|
||||
public function getLoadClassNamespaceCollisionTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
),
|
||||
'\Apc\NamespaceCollision\A\Foo',
|
||||
'Apc\NamespaceCollision\A\Foo',
|
||||
'->loadClass() loads NamespaceCollision\A\Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
@@ -118,7 +116,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
),
|
||||
'\Apc\NamespaceCollision\A\Bar',
|
||||
'Apc\NamespaceCollision\A\Bar',
|
||||
'->loadClass() loads NamespaceCollision\A\Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
@@ -126,7 +124,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
),
|
||||
'\Apc\NamespaceCollision\A\B\Foo',
|
||||
'Apc\NamespaceCollision\A\B\Foo',
|
||||
'->loadClass() loads NamespaceCollision\A\B\Foo from beta.',
|
||||
),
|
||||
array(
|
||||
@@ -134,11 +132,11 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
),
|
||||
'\Apc\NamespaceCollision\A\B\Bar',
|
||||
'Apc\NamespaceCollision\A\B\Bar',
|
||||
'->loadClass() loads NamespaceCollision\A\B\Bar from beta.',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassPrefixCollisionTests
|
||||
@@ -152,9 +150,9 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassPrefixCollisionTests()
|
||||
{
|
||||
return array(
|
||||
public function getLoadClassPrefixCollisionTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
@@ -188,5 +186,5 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
'->loadClass() loads ApcPrefixCollision_A_B_Bar from beta.',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testTraitDependencies()
|
||||
{
|
||||
if (version_compare(phpversion(), '5.4', '<')) {
|
||||
if (PHP_VERSION_ID < 50400) {
|
||||
$this->markTestSkipped('Requires PHP > 5.4');
|
||||
|
||||
return;
|
||||
@@ -100,7 +100,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testClassWithTraitsReordering(array $classes)
|
||||
{
|
||||
if (version_compare(phpversion(), '5.4', '<')) {
|
||||
if (PHP_VERSION_ID < 50400) {
|
||||
$this->markTestSkipped('Requires PHP > 5.4');
|
||||
|
||||
return;
|
||||
@@ -146,6 +146,38 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testFixClassWithTraitsOrdering()
|
||||
{
|
||||
if (PHP_VERSION_ID < 50400) {
|
||||
$this->markTestSkipped('Requires PHP > 5.4');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/CTrait.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/F.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/G.php';
|
||||
|
||||
$classes = array(
|
||||
'ClassesWithParents\\F',
|
||||
'ClassesWithParents\\G',
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
'ClassesWithParents\\CTrait',
|
||||
'ClassesWithParents\\F',
|
||||
'ClassesWithParents\\G',
|
||||
);
|
||||
|
||||
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
|
||||
|
||||
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFixNamespaceDeclarationsData
|
||||
*/
|
||||
@@ -227,7 +259,7 @@ class WithComments
|
||||
{
|
||||
public static \$loaded = true;
|
||||
}
|
||||
\$string ='string shoult not be modified {\$string}';
|
||||
\$string ='string should not be modified {\$string}';
|
||||
\$heredoc = (<<<HD
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ use Symfony\Component\ClassLoader\ClassMapGenerator;
|
||||
class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var string $workspace
|
||||
* @var string|null
|
||||
*/
|
||||
private $workspace = null;
|
||||
|
||||
@@ -72,11 +72,11 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$data = array(
|
||||
array(__DIR__.'/Fixtures/Namespaced', array(
|
||||
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.php',
|
||||
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
|
||||
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
|
||||
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.php',
|
||||
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
|
||||
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
|
||||
'Namespaced\\WithComments' => realpath(__DIR__).'/Fixtures/Namespaced/WithComments.php',
|
||||
)
|
||||
),
|
||||
),
|
||||
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array(
|
||||
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
|
||||
@@ -85,26 +85,26 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
'NamespaceCollision\\C\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Foo.php',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/Pearlike', array(
|
||||
'Pearlike_Foo' => realpath(__DIR__).'/Fixtures/Pearlike/Foo.php',
|
||||
'Pearlike_Bar' => realpath(__DIR__).'/Fixtures/Pearlike/Bar.php',
|
||||
'Pearlike_Baz' => realpath(__DIR__).'/Fixtures/Pearlike/Baz.php',
|
||||
'Pearlike_Foo' => realpath(__DIR__).'/Fixtures/Pearlike/Foo.php',
|
||||
'Pearlike_Bar' => realpath(__DIR__).'/Fixtures/Pearlike/Bar.php',
|
||||
'Pearlike_Baz' => realpath(__DIR__).'/Fixtures/Pearlike/Baz.php',
|
||||
'Pearlike_WithComments' => realpath(__DIR__).'/Fixtures/Pearlike/WithComments.php',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/classmap', array(
|
||||
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
||||
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
||||
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Beta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
||||
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
||||
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Beta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php',
|
||||
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
|
||||
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
|
||||
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
|
||||
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
|
||||
)),
|
||||
);
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.4', '>=')) {
|
||||
if (PHP_VERSION_ID >= 50400) {
|
||||
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
|
||||
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
@@ -120,10 +120,6 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testCreateMapFinderSupport()
|
||||
{
|
||||
if (!class_exists('Symfony\\Component\\Finder\\Finder')) {
|
||||
$this->markTestSkipped('Finder component is not available');
|
||||
}
|
||||
|
||||
$finder = new \Symfony\Component\Finder\Finder();
|
||||
$finder->files()->in(__DIR__.'/Fixtures/beta/NamespaceCollision');
|
||||
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
class A extends B {}
|
||||
class A extends B
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
class B implements CInterface {}
|
||||
class B implements CInterface
|
||||
{
|
||||
}
|
||||
|
||||
8
Tests/Fixtures/ClassesWithParents/F.php
Normal file
8
Tests/Fixtures/ClassesWithParents/F.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
class F
|
||||
{
|
||||
use CTrait;
|
||||
}
|
||||
8
Tests/Fixtures/ClassesWithParents/G.php
Normal file
8
Tests/Fixtures/ClassesWithParents/G.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
class G
|
||||
{
|
||||
use CTrait;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ class WithComments
|
||||
public static $loaded = true;
|
||||
}
|
||||
|
||||
$string = 'string shoult not be modified {$string}';
|
||||
$string = 'string should not be modified {$string}';
|
||||
|
||||
$heredoc = (<<<HD
|
||||
|
||||
|
||||
@@ -13,5 +13,4 @@ namespace ClassMap;
|
||||
|
||||
class SomeClass extends SomeParent implements SomeInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -13,5 +13,4 @@ namespace ClassMap;
|
||||
|
||||
interface SomeInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -13,5 +13,4 @@ namespace ClassMap;
|
||||
|
||||
abstract class SomeParent
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace {
|
||||
class A {}
|
||||
class A
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
namespace Alpha {
|
||||
class A {}
|
||||
class B {}
|
||||
class A
|
||||
{
|
||||
}
|
||||
class B
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
namespace Beta {
|
||||
class A {}
|
||||
class B {}
|
||||
class A
|
||||
{
|
||||
}
|
||||
class B
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,9 @@
|
||||
|
||||
namespace Foo\Bar;
|
||||
|
||||
class A {}
|
||||
class B {}
|
||||
class A
|
||||
{
|
||||
}
|
||||
class B
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
trait TD
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
trait TZ
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace {
|
||||
trait TFoo
|
||||
{
|
||||
@@ -25,6 +26,7 @@ namespace Foo {
|
||||
|
||||
class CBar implements IBar
|
||||
{
|
||||
use TBar, TFooBar;
|
||||
use TBar;
|
||||
use TFooBar;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ namespace Symfony\Component\ClassLoader;
|
||||
* // register classes with namespaces
|
||||
* $loader->registerNamespaces(array(
|
||||
* 'Symfony\Component' => __DIR__.'/component',
|
||||
* 'Symfony' => __DIR__.'/framework',
|
||||
* 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
|
||||
* 'Symfony' => __DIR__.'/framework',
|
||||
* 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
|
||||
* ));
|
||||
*
|
||||
* // register a library using the PEAR naming convention
|
||||
@@ -68,20 +68,20 @@ class UniversalClassLoader
|
||||
|
||||
/**
|
||||
* Turns on searching the include for class files. Allows easy loading
|
||||
* of installed PEAR packages
|
||||
* of installed PEAR packages.
|
||||
*
|
||||
* @param Boolean $useIncludePath
|
||||
* @param bool $useIncludePath
|
||||
*/
|
||||
public function useIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
$this->useIncludePath = (bool) $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return Boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
@@ -173,7 +173,7 @@ class UniversalClassLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an array of namespaces
|
||||
* Registers an array of namespaces.
|
||||
*
|
||||
* @param array $namespaces An array of namespaces (namespaces as keys and locations as values)
|
||||
*
|
||||
@@ -229,7 +229,7 @@ class UniversalClassLoader
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param Boolean $prepend Whether to prepend the autoloader or not
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -243,7 +243,7 @@ class UniversalClassLoader
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return Boolean|null True, if loaded
|
||||
* @return bool|null True, if loaded
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
@@ -287,7 +287,6 @@ class UniversalClassLoader
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$normalizedClass = str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
|
||||
|
||||
@@ -17,11 +17,19 @@ namespace Symfony\Component\ClassLoader;
|
||||
* 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 autoloader following this convention (the Composer one for instance)
|
||||
* 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');
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* // or with a Composer autoloader
|
||||
* use Composer\Autoload\ClassLoader;
|
||||
*
|
||||
* $loader = new ClassLoader();
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
@@ -43,18 +51,17 @@ class WinCacheClassLoader
|
||||
private $prefix;
|
||||
|
||||
/**
|
||||
* The class loader object being decorated.
|
||||
* A class loader object that implements the findFile() method.
|
||||
*
|
||||
* @var \Symfony\Component\ClassLoader\ClassLoader
|
||||
* A class loader object that implements the findFile() method.
|
||||
* @var object
|
||||
*/
|
||||
protected $decorated;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $prefix The WinCache namespace prefix to use.
|
||||
* @param object $decorated A class loader object that implements the findFile() method.
|
||||
* @param string $prefix The WinCache namespace prefix to use.
|
||||
* @param object $decorated A class loader object that implements the findFile() method.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @throws \InvalidArgumentException
|
||||
@@ -76,7 +83,7 @@ class WinCacheClassLoader
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param Boolean $prepend Whether to prepend the autoloader or not
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
@@ -96,7 +103,7 @@ class WinCacheClassLoader
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return Boolean|null True, if loaded
|
||||
* @return bool|null True, if loaded
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
|
||||
@@ -12,16 +12,24 @@
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
/**
|
||||
* XcacheClassLoader implements a wrapping autoloader cached in Xcache for PHP 5.3.
|
||||
* XcacheClassLoader implements a wrapping autoloader cached in XCache for PHP 5.3.
|
||||
*
|
||||
* 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 autoloader following this convention (the Composer one for instance)
|
||||
* 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');
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* // or with a Composer autoloader
|
||||
* use Composer\Autoload\ClassLoader;
|
||||
*
|
||||
* $loader = new ClassLoader();
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
@@ -43,37 +51,43 @@ namespace Symfony\Component\ClassLoader;
|
||||
class XcacheClassLoader
|
||||
{
|
||||
private $prefix;
|
||||
private $classFinder;
|
||||
|
||||
/**
|
||||
* A class loader object that implements the findFile() method.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $decorated;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $prefix A prefix to create a namespace in Xcache
|
||||
* @param object $classFinder An object that implements findFile() method.
|
||||
* @param string $prefix The XCache namespace prefix to use.
|
||||
* @param object $decorated A class loader object that implements the findFile() method.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($prefix, $classFinder)
|
||||
public function __construct($prefix, $decorated)
|
||||
{
|
||||
if (!extension_loaded('Xcache')) {
|
||||
throw new \RuntimeException('Unable to use XcacheClassLoader as Xcache is not enabled.');
|
||||
if (!extension_loaded('xcache')) {
|
||||
throw new \RuntimeException('Unable to use XcacheClassLoader as XCache is not enabled.');
|
||||
}
|
||||
|
||||
if (!method_exists($classFinder, 'findFile')) {
|
||||
if (!method_exists($decorated, 'findFile')) {
|
||||
throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
|
||||
}
|
||||
|
||||
$this->prefix = $prefix;
|
||||
$this->classFinder = $classFinder;
|
||||
$this->decorated = $decorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param Boolean $prepend Whether to prepend the autoloader or not
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
@@ -93,7 +107,7 @@ class XcacheClassLoader
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return Boolean|null True, if loaded
|
||||
* @return bool|null True, if loaded
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
@@ -116,9 +130,18 @@ class XcacheClassLoader
|
||||
if (xcache_isset($this->prefix.$class)) {
|
||||
$file = xcache_get($this->prefix.$class);
|
||||
} else {
|
||||
xcache_set($this->prefix.$class, $file = $this->classFinder->findFile($class));
|
||||
$file = $this->decorated->findFile($class);
|
||||
xcache_set($this->prefix.$class, $file);
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes through all unknown calls onto the decorated object.
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return call_user_func_array(array($this->decorated, $method), $args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"type": "library",
|
||||
"description": "Symfony ClassLoader Component",
|
||||
"keywords": [],
|
||||
"homepage": "http://symfony.com",
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
@@ -12,7 +12,7 @@
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "http://symfony.com/contributors"
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
@@ -20,7 +20,8 @@
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/finder": "~2.0"
|
||||
"symfony/phpunit-bridge": "~2.7",
|
||||
"symfony/finder": "~2.0,>=2.0.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Symfony\\Component\\ClassLoader\\": "" }
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
>
|
||||
<php>
|
||||
<ini name="error_reporting" value="-1" />
|
||||
</php>
|
||||
<testsuites>
|
||||
<testsuite name="Symfony ClassLoader Component Test Suite">
|
||||
<directory>./Tests/</directory>
|
||||
|
||||
Reference in New Issue
Block a user