mirror of
https://github.com/symfony/class-loader.git
synced 2026-03-24 09:12:18 +01:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a01933a8d | ||
|
|
d77ac7df59 | ||
|
|
355a6b3ee2 | ||
|
|
ac7c135db5 | ||
|
|
71ff8cc2af | ||
|
|
136d713362 | ||
|
|
72df2d4535 | ||
|
|
a08420fb07 | ||
|
|
6dc4479622 | ||
|
|
6abee87b00 | ||
|
|
f43622ab16 | ||
|
|
7b12dc6915 | ||
|
|
f604d121fa | ||
|
|
c77176c94f | ||
|
|
25d492fa74 | ||
|
|
bd1ffcea9c | ||
|
|
f0a379b040 | ||
|
|
a4e0538494 | ||
|
|
2ae3b6f88a | ||
|
|
480abf8101 | ||
|
|
7c31a493f4 | ||
|
|
89922ecb2b | ||
|
|
00efe62b37 | ||
|
|
4a439e796e | ||
|
|
519ac47b5f | ||
|
|
e0d78d3cfd | ||
|
|
931f370587 | ||
|
|
b9ce73294e | ||
|
|
82f4e6502e | ||
|
|
598dfd4610 | ||
|
|
85b2532f2f | ||
|
|
1ecb64f0c2 | ||
|
|
cc6272033e |
@@ -44,8 +44,6 @@ namespace Symfony\Component\ClassLoader;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class ApcClassLoader
|
||||
{
|
||||
@@ -66,13 +64,11 @@ class ApcClassLoader
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($prefix, $decorated)
|
||||
{
|
||||
if (!extension_loaded('apc')) {
|
||||
throw new \RuntimeException('Unable to use ApcClassLoader as APC is not enabled.');
|
||||
if (!function_exists('apcu_fetch')) {
|
||||
throw new \RuntimeException('Unable to use ApcClassLoader as APC is not installed.');
|
||||
}
|
||||
|
||||
if (!method_exists($decorated, 'findFile')) {
|
||||
@@ -126,8 +122,10 @@ class ApcClassLoader
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
if (false === $file = apc_fetch($this->prefix.$class)) {
|
||||
apc_store($this->prefix.$class, $file = $this->decorated->findFile($class));
|
||||
$file = apcu_fetch($this->prefix.$class, $success);
|
||||
|
||||
if (!$success) {
|
||||
apcu_store($this->prefix.$class, $file = $this->decorated->findFile($class) ?: null);
|
||||
}
|
||||
|
||||
return $file;
|
||||
|
||||
@@ -57,8 +57,6 @@ namespace Symfony\Component\ClassLoader;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class ApcUniversalClassLoader extends UniversalClassLoader
|
||||
{
|
||||
@@ -70,12 +68,10 @@ class ApcUniversalClassLoader extends UniversalClassLoader
|
||||
* @param string $prefix A prefix to create a namespace in APC
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($prefix)
|
||||
{
|
||||
if (!extension_loaded('apc')) {
|
||||
if (!function_exists('apcu_fetch')) {
|
||||
throw new \RuntimeException('Unable to use ApcUniversalClassLoader as APC is not enabled.');
|
||||
}
|
||||
|
||||
@@ -91,8 +87,10 @@ class ApcUniversalClassLoader extends UniversalClassLoader
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
if (false === $file = apc_fetch($this->prefix.$class)) {
|
||||
apc_store($this->prefix.$class, $file = parent::findFile($class));
|
||||
$file = apcu_fetch($this->prefix.$class, $success);
|
||||
|
||||
if (!$success) {
|
||||
apcu_store($this->prefix.$class, $file = parent::findFile($class) ?: null);
|
||||
}
|
||||
|
||||
return $file;
|
||||
|
||||
@@ -116,8 +116,8 @@ class ClassCollectionLoader
|
||||
}
|
||||
|
||||
// cache the core classes
|
||||
if (!is_dir(dirname($cache))) {
|
||||
mkdir(dirname($cache), 0777, true);
|
||||
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
|
||||
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
|
||||
}
|
||||
self::writeCacheFile($cache, '<?php '.$content);
|
||||
|
||||
@@ -137,8 +137,8 @@ class ClassCollectionLoader
|
||||
public static function fixNamespaceDeclarations($source)
|
||||
{
|
||||
if (!function_exists('token_get_all') || !self::$useTokenizer) {
|
||||
if (preg_match('/namespace(.*?)\s*;/', $source)) {
|
||||
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
|
||||
if (preg_match('/(^|\s)namespace(.*?)\s*;/', $source)) {
|
||||
$source = preg_replace('/(^|\s)namespace(.*?)\s*;/', "$1namespace$2\n{", $source)."}\n";
|
||||
}
|
||||
|
||||
return $source;
|
||||
@@ -149,8 +149,9 @@ class ClassCollectionLoader
|
||||
$inNamespace = false;
|
||||
$tokens = token_get_all($source);
|
||||
|
||||
for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
|
||||
if (is_string($token)) {
|
||||
for ($i = 0; isset($tokens[$i]); ++$i) {
|
||||
$token = $tokens[$i];
|
||||
if (!isset($token[1]) || 'b"' === $token) {
|
||||
$rawChunk .= $token;
|
||||
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
|
||||
// strip comments
|
||||
@@ -162,12 +163,12 @@ class ClassCollectionLoader
|
||||
$rawChunk .= $token[1];
|
||||
|
||||
// namespace name and whitespaces
|
||||
while (($t = next($tokens)) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
|
||||
$rawChunk .= $t[1];
|
||||
while (isset($tokens[++$i][1]) && in_array($tokens[$i][0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
|
||||
$rawChunk .= $tokens[$i][1];
|
||||
}
|
||||
if ('{' === $t) {
|
||||
if ('{' === $tokens[$i]) {
|
||||
$inNamespace = false;
|
||||
prev($tokens);
|
||||
--$i;
|
||||
} else {
|
||||
$rawChunk = rtrim($rawChunk)."\n{";
|
||||
$inNamespace = true;
|
||||
@@ -175,8 +176,8 @@ class ClassCollectionLoader
|
||||
} elseif (T_START_HEREDOC === $token[0]) {
|
||||
$output .= self::compressCode($rawChunk).$token[1];
|
||||
do {
|
||||
$token = next($tokens);
|
||||
$output .= is_string($token) ? $token : $token[1];
|
||||
$token = $tokens[++$i];
|
||||
$output .= isset($token[1]) && 'b"' !== $token ? $token[1] : $token;
|
||||
} while ($token[0] !== T_END_HEREDOC);
|
||||
$output .= "\n";
|
||||
$rawChunk = '';
|
||||
@@ -192,7 +193,15 @@ class ClassCollectionLoader
|
||||
$rawChunk .= "}\n";
|
||||
}
|
||||
|
||||
return $output.self::compressCode($rawChunk);
|
||||
$output .= self::compressCode($rawChunk);
|
||||
|
||||
if (PHP_VERSION_ID >= 70000) {
|
||||
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
|
||||
unset($tokens, $rawChunk);
|
||||
gc_mem_caches();
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,7 +292,7 @@ class ClassCollectionLoader
|
||||
|
||||
$traits = array();
|
||||
|
||||
if (function_exists('get_declared_traits')) {
|
||||
if (method_exists('ReflectionClass', 'getTraits')) {
|
||||
foreach ($classes as $c) {
|
||||
foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
|
||||
if ($trait !== $c) {
|
||||
|
||||
@@ -91,12 +91,16 @@ class ClassLoader
|
||||
return;
|
||||
}
|
||||
if (isset($this->prefixes[$prefix])) {
|
||||
$this->prefixes[$prefix] = array_merge(
|
||||
$this->prefixes[$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
if (is_array($paths)) {
|
||||
$this->prefixes[$prefix] = array_unique(array_merge(
|
||||
$this->prefixes[$prefix],
|
||||
$paths
|
||||
));
|
||||
} elseif (!in_array($paths, $this->prefixes[$prefix])) {
|
||||
$this->prefixes[$prefix][] = $paths;
|
||||
}
|
||||
} else {
|
||||
$this->prefixes[$prefix] = (array) $paths;
|
||||
$this->prefixes[$prefix] = array_unique((array) $paths);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,11 @@ class ClassMapGenerator
|
||||
|
||||
$classes = self::findClasses($path);
|
||||
|
||||
if (PHP_VERSION_ID >= 70000) {
|
||||
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
|
||||
gc_mem_caches();
|
||||
}
|
||||
|
||||
foreach ($classes as $class) {
|
||||
$map[$class] = $path;
|
||||
}
|
||||
@@ -95,10 +100,10 @@ class ClassMapGenerator
|
||||
$classes = array();
|
||||
|
||||
$namespace = '';
|
||||
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
|
||||
for ($i = 0; isset($tokens[$i]); ++$i) {
|
||||
$token = $tokens[$i];
|
||||
|
||||
if (is_string($token)) {
|
||||
if (!isset($token[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -108,9 +113,9 @@ class ClassMapGenerator
|
||||
case T_NAMESPACE:
|
||||
$namespace = '';
|
||||
// If there is a namespace, extract it
|
||||
while (($t = $tokens[++$i]) && is_array($t)) {
|
||||
if (in_array($t[0], array(T_STRING, T_NS_SEPARATOR))) {
|
||||
$namespace .= $t[1];
|
||||
while (isset($tokens[++$i][1])) {
|
||||
if (in_array($tokens[$i][0], array(T_STRING, T_NS_SEPARATOR))) {
|
||||
$namespace .= $tokens[$i][1];
|
||||
}
|
||||
}
|
||||
$namespace .= '\\';
|
||||
@@ -118,11 +123,31 @@ class ClassMapGenerator
|
||||
case T_CLASS:
|
||||
case T_INTERFACE:
|
||||
case SYMFONY_TRAIT:
|
||||
// Skip usage of ::class constant
|
||||
$isClassConstant = false;
|
||||
for ($j = $i - 1; $j > 0; --$j) {
|
||||
if (!isset($tokens[$j][1])) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (T_DOUBLE_COLON === $tokens[$j][0]) {
|
||||
$isClassConstant = true;
|
||||
break;
|
||||
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isClassConstant) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Find the classname
|
||||
while (($t = $tokens[++$i]) && is_array($t)) {
|
||||
while (isset($tokens[++$i][1])) {
|
||||
$t = $tokens[$i];
|
||||
if (T_STRING === $t[0]) {
|
||||
$class .= $t[1];
|
||||
} elseif ($class !== '' && T_WHITESPACE == $t[0]) {
|
||||
} elseif ('' !== $class && T_WHITESPACE === $t[0]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ namespace Symfony\Component\ClassLoader;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Christophe Coevoet <stof@notk.org>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class DebugClassLoader
|
||||
{
|
||||
@@ -31,8 +29,6 @@ class DebugClassLoader
|
||||
* Constructor.
|
||||
*
|
||||
* @param object $classFinder
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($classFinder)
|
||||
{
|
||||
@@ -78,7 +74,7 @@ class DebugClassLoader
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
return $this->classFinder->findFile($class);
|
||||
return $this->classFinder->findFile($class) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2004-2015 Fabien Potencier
|
||||
Copyright (c) 2004-2016 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
|
||||
|
||||
85
README.md
85
README.md
@@ -1,85 +1,14 @@
|
||||
ClassLoader Component
|
||||
=====================
|
||||
|
||||
ClassLoader loads your project classes automatically if they follow some
|
||||
standard PHP conventions.
|
||||
|
||||
The ClassLoader object is able to autoload classes that implement the PSR-0
|
||||
standard or the PEAR naming convention.
|
||||
|
||||
First, register the autoloader:
|
||||
|
||||
```php
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
|
||||
|
||||
use Symfony\Component\ClassLoader\ClassLoader;
|
||||
|
||||
$loader = new ClassLoader();
|
||||
$loader->register();
|
||||
```
|
||||
|
||||
Then, register some namespaces with the `addPrefix()` method:
|
||||
|
||||
```php
|
||||
$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.
|
||||
|
||||
You can also register a sub-namespaces:
|
||||
|
||||
```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:
|
||||
|
||||
```php
|
||||
$loader->addPrefix('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
|
||||
```
|
||||
|
||||
Alternatively, you can use the `addPrefixes()` method to register more
|
||||
than one namespace at once:
|
||||
|
||||
```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 class loader:
|
||||
|
||||
```php
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcClassLoader.php';
|
||||
|
||||
use Symfony\Component\ClassLoader\ClassLoader;
|
||||
use Symfony\Component\ClassLoader\ApcClassLoader;
|
||||
|
||||
$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
|
||||
provide byte caches.
|
||||
The ClassLoader component provides tools to autoload your classes and cache
|
||||
their locations for performance.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
You can run the unit tests with the following command:
|
||||
|
||||
$ cd path/to/Symfony/Component/ClassLoader/
|
||||
$ composer install
|
||||
$ phpunit
|
||||
* [Documentation](https://symfony.com/doc/current/components/class_loader/index.html)
|
||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||
in the [main Symfony repository](https://github.com/symfony/symfony)
|
||||
|
||||
@@ -17,21 +17,17 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!extension_loaded('apc')) {
|
||||
$this->markTestSkipped('The apc extension is not available.');
|
||||
}
|
||||
|
||||
if (!(ini_get('apc.enabled') && ini_get('apc.enable_cli'))) {
|
||||
$this->markTestSkipped('The apc extension is available, but not enabled.');
|
||||
if (ini_get('apc.enabled') && ini_get('apc.enable_cli')) {
|
||||
apcu_clear_cache();
|
||||
} else {
|
||||
apc_clear_cache('user');
|
||||
$this->markTestSkipped('APC is not enabled.');
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (ini_get('apc.enabled') && ini_get('apc.enable_cli')) {
|
||||
apc_clear_cache('user');
|
||||
apcu_clear_cache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +36,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.');
|
||||
$loader->registerNamespace('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
|
||||
$this->assertEquals($loader->findFile('\Apc\Namespaced\FooBar'), apc_fetch('test.prefix.\Apc\Namespaced\FooBar'), '__construct() takes a prefix as its first argument');
|
||||
$this->assertEquals($loader->findFile('\Apc\Namespaced\FooBar'), apcu_fetch('test.prefix.\Apc\Namespaced\FooBar'), '__construct() takes a prefix as its first argument');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,14 +20,11 @@ require_once __DIR__.'/Fixtures/ClassesWithParents/A.php';
|
||||
|
||||
class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 5.4
|
||||
*/
|
||||
public function testTraitDependencies()
|
||||
{
|
||||
if (PHP_VERSION_ID < 50400) {
|
||||
$this->markTestSkipped('Requires PHP > 5.4');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
require_once __DIR__.'/Fixtures/deps/traits.php';
|
||||
|
||||
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
|
||||
@@ -97,15 +94,10 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @dataProvider getDifferentOrdersForTraits
|
||||
* @requires PHP 5.4
|
||||
*/
|
||||
public function testClassWithTraitsReordering(array $classes)
|
||||
{
|
||||
if (PHP_VERSION_ID < 50400) {
|
||||
$this->markTestSkipped('Requires PHP > 5.4');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/ATrait.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/BTrait.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/CTrait.php';
|
||||
@@ -146,14 +138,11 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.4
|
||||
*/
|
||||
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';
|
||||
@@ -216,7 +205,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
array("namespace Bar ;\nclass Foo {}\n", "namespace Bar\n{\nclass Foo {}\n}\n"),
|
||||
array("namespace Foo\Bar;\nclass Foo {}\n", "namespace Foo\Bar\n{\nclass Foo {}\n}\n"),
|
||||
array("namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n", "namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n"),
|
||||
array("namespace\n{\nclass Foo {}\n}\n", "namespace\n{\nclass Foo {}\n}\n"),
|
||||
array("\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n", "\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -252,26 +241,26 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
spl_autoload_unregister($r);
|
||||
|
||||
$this->assertEquals(<<<EOF
|
||||
$this->assertEquals(<<<'EOF'
|
||||
namespace Namespaced
|
||||
{
|
||||
class WithComments
|
||||
{
|
||||
public static \$loaded = true;
|
||||
public static $loaded = true;
|
||||
}
|
||||
\$string ='string should not be modified {\$string}';
|
||||
\$heredoc = (<<<HD
|
||||
$string ='string should not be modified {$string}';
|
||||
$heredoc = (<<<HD
|
||||
|
||||
|
||||
Heredoc should not be modified {\$string}
|
||||
Heredoc should not be modified {$string}
|
||||
|
||||
|
||||
HD
|
||||
);
|
||||
\$nowdoc =<<<'ND'
|
||||
$nowdoc =<<<'ND'
|
||||
|
||||
|
||||
Nowdoc should not be modified {\$string}
|
||||
Nowdoc should not be modified {$string}
|
||||
|
||||
|
||||
ND
|
||||
@@ -281,7 +270,7 @@ namespace
|
||||
{
|
||||
class Pearlike_WithComments
|
||||
{
|
||||
public static \$loaded = true;
|
||||
public static $loaded = true;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
@@ -76,14 +76,36 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddPrefix()
|
||||
public function testAddPrefixSingle()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$prefixes = $loader->getPrefixes();
|
||||
$this->assertArrayHasKey('Foo', $prefixes);
|
||||
$this->assertCount(1, $prefixes['Foo']);
|
||||
}
|
||||
|
||||
public function testAddPrefixesSingle()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefixes(array('Foo' => array('foo', 'foo')));
|
||||
$loader->addPrefixes(array('Foo' => array('foo')));
|
||||
$prefixes = $loader->getPrefixes();
|
||||
$this->assertArrayHasKey('Foo', $prefixes);
|
||||
$this->assertCount(1, $prefixes['Foo'], print_r($prefixes, true));
|
||||
}
|
||||
|
||||
public function testAddPrefixMulti()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Foo', 'foo');
|
||||
$loader->addPrefix('Foo', 'bar');
|
||||
$prefixes = $loader->getPrefixes();
|
||||
$this->assertArrayHasKey('Foo', $prefixes);
|
||||
$this->assertCount(2, $prefixes['Foo']);
|
||||
$this->assertContains('foo', $prefixes['Foo']);
|
||||
$this->assertContains('bar', $prefixes['Foo']);
|
||||
}
|
||||
|
||||
public function testUseIncludePath()
|
||||
|
||||
@@ -22,7 +22,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function prepare_workspace()
|
||||
{
|
||||
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().rand(0, 1000);
|
||||
$this->workspace = sys_get_temp_dir().'/'.microtime(true).'.'.mt_rand();
|
||||
mkdir($this->workspace, 0777, true);
|
||||
$this->workspace = realpath($this->workspace);
|
||||
}
|
||||
@@ -47,7 +47,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @dataProvider getTestCreateMapTests
|
||||
*/
|
||||
public function testDump($directory, $expected)
|
||||
public function testDump($directory)
|
||||
{
|
||||
$this->prepare_workspace();
|
||||
|
||||
@@ -115,6 +115,12 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
));
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID >= 50500) {
|
||||
$data[] = array(__DIR__.'/Fixtures/php5.5', array(
|
||||
'ClassCons\\Foo' => __DIR__.'/Fixtures/php5.5/class_cons.php',
|
||||
));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -134,10 +140,10 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
protected function assertEqualsNormalized($expected, $actual, $message = null)
|
||||
{
|
||||
foreach ($expected as $ns => $path) {
|
||||
$expected[$ns] = strtr($path, '\\', '/');
|
||||
$expected[$ns] = str_replace('\\', '/', $path);
|
||||
}
|
||||
foreach ($actual as $ns => $path) {
|
||||
$actual[$ns] = strtr($path, '\\', '/');
|
||||
$actual[$ns] = str_replace('\\', '/', $path);
|
||||
}
|
||||
$this->assertEquals($expected, $actual, $message);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace {
|
||||
class A
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace {
|
||||
trait TFoo
|
||||
{
|
||||
|
||||
11
Tests/Fixtures/php5.5/class_cons.php
Normal file
11
Tests/Fixtures/php5.5/class_cons.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace ClassCons;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
\Foo\TBar/* foo */::class;
|
||||
}
|
||||
}
|
||||
@@ -55,8 +55,6 @@ namespace Symfony\Component\ClassLoader;
|
||||
* found before giving up.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class UniversalClassLoader
|
||||
{
|
||||
@@ -132,8 +130,6 @@ class UniversalClassLoader
|
||||
* Registers the directory to use as a fallback for namespaces.
|
||||
*
|
||||
* @param array $dirs An array of directories
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function registerNamespaceFallbacks(array $dirs)
|
||||
{
|
||||
@@ -154,8 +150,6 @@ class UniversalClassLoader
|
||||
* Registers directories to use as a fallback for class prefixes.
|
||||
*
|
||||
* @param array $dirs An array of directories
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function registerPrefixFallbacks(array $dirs)
|
||||
{
|
||||
@@ -176,8 +170,6 @@ class UniversalClassLoader
|
||||
* 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)
|
||||
{
|
||||
@@ -191,8 +183,6 @@ class UniversalClassLoader
|
||||
*
|
||||
* @param string $namespace The namespace
|
||||
* @param array|string $paths The location(s) of the namespace
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function registerNamespace($namespace, $paths)
|
||||
{
|
||||
@@ -203,8 +193,6 @@ class UniversalClassLoader
|
||||
* 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)
|
||||
{
|
||||
@@ -218,8 +206,6 @@ class UniversalClassLoader
|
||||
*
|
||||
* @param string $prefix The classes prefix
|
||||
* @param array|string $paths The location(s) of the classes
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function registerPrefix($prefix, $paths)
|
||||
{
|
||||
@@ -230,8 +216,6 @@ class UniversalClassLoader
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
|
||||
@@ -123,8 +123,10 @@ class WinCacheClassLoader
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
if (false === $file = wincache_ucache_get($this->prefix.$class)) {
|
||||
wincache_ucache_set($this->prefix.$class, $file = $this->decorated->findFile($class), 0);
|
||||
$file = wincache_ucache_get($this->prefix.$class, $success);
|
||||
|
||||
if (!$success) {
|
||||
wincache_ucache_set($this->prefix.$class, $file = $this->decorated->findFile($class) ?: null, 0);
|
||||
}
|
||||
|
||||
return $file;
|
||||
|
||||
@@ -45,8 +45,6 @@ namespace Symfony\Component\ClassLoader;
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class XcacheClassLoader
|
||||
{
|
||||
@@ -67,8 +65,6 @@ class XcacheClassLoader
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($prefix, $decorated)
|
||||
{
|
||||
@@ -130,7 +126,7 @@ class XcacheClassLoader
|
||||
if (xcache_isset($this->prefix.$class)) {
|
||||
$file = xcache_get($this->prefix.$class);
|
||||
} else {
|
||||
$file = $this->decorated->findFile($class);
|
||||
$file = $this->decorated->findFile($class) ?: null;
|
||||
xcache_set($this->prefix.$class, $file);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"type": "library",
|
||||
"description": "Symfony ClassLoader Component",
|
||||
"keywords": [],
|
||||
"homepage": "http://symfony.com",
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
@@ -12,19 +12,22 @@
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "http://symfony.com/contributors"
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
"php": ">=5.3.3",
|
||||
"symfony/polyfill-apcu": "~1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/phpunit-bridge": "~2.7",
|
||||
"symfony/finder": "~2.0,>=2.0.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Symfony\\Component\\ClassLoader\\": "" }
|
||||
"psr-0": { "Symfony\\Component\\ClassLoader\\": "" },
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"target-dir": "Symfony/Component/ClassLoader",
|
||||
"extra": {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<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