mirror of
https://github.com/symfony/class-loader.git
synced 2026-03-24 17:22:11 +01:00
Compare commits
120 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a22265a9f3 | ||
|
|
df12a498a6 | ||
|
|
30ec6eb319 | ||
|
|
4afd812a39 | ||
|
|
17092401a4 | ||
|
|
5e119b7df5 | ||
|
|
04a7e4c1bf | ||
|
|
e4636a4f23 | ||
|
|
bcdf6ff46e | ||
|
|
a016c360a5 | ||
|
|
e212b06996 | ||
|
|
5a37725821 | ||
|
|
bfe1178328 | ||
|
|
4860dcded1 | ||
|
|
4459eef529 | ||
|
|
4513348012 | ||
|
|
420458095c | ||
|
|
8194721a1e | ||
|
|
5605edec7b | ||
|
|
5694f145b1 | ||
|
|
f31333bdff | ||
|
|
11b1f30ef9 | ||
|
|
31db283fc8 | ||
|
|
f65a559906 | ||
|
|
3716acff65 | ||
|
|
351b74b156 | ||
|
|
dadfb73e2f | ||
|
|
ebdecd509e | ||
|
|
e63c126998 | ||
|
|
e17eb698fd | ||
|
|
f87f46e5e1 | ||
|
|
78710673c0 | ||
|
|
192c1b0522 | ||
|
|
6295e4cd5c | ||
|
|
a50bb5c44e | ||
|
|
9dac4c57cf | ||
|
|
a447ad59a4 | ||
|
|
da1adbf5c0 | ||
|
|
ff0b32db69 | ||
|
|
59ab31e13c | ||
|
|
e8d36a7b55 | ||
|
|
df173ac2af | ||
|
|
5d7aa644f5 | ||
|
|
eb2590d94c | ||
|
|
e327469117 | ||
|
|
39e778f25a | ||
|
|
5990564047 | ||
|
|
5d77753a96 | ||
|
|
2141b7653a | ||
|
|
7572c904b2 | ||
|
|
f735c66436 | ||
|
|
f4278d53d1 | ||
|
|
9ae87e8c34 | ||
|
|
295a2897de | ||
|
|
a61248e1a8 | ||
|
|
13eed20cc4 | ||
|
|
f8843095b2 | ||
|
|
1635a4c8fe | ||
|
|
9c69968ce5 | ||
|
|
151afda88c | ||
|
|
2c4235602f | ||
|
|
379123b6b8 | ||
|
|
386a294d62 | ||
|
|
9ff12bbe71 | ||
|
|
168245af83 | ||
|
|
e192d96b15 | ||
|
|
48b96f2fa9 | ||
|
|
8bfdaa2e7a | ||
|
|
6bf941dc4e | ||
|
|
cf3e7ac373 | ||
|
|
8c7ae3c4e3 | ||
|
|
b0aff75bf1 | ||
|
|
fc4c04bfd1 | ||
|
|
6789dc86c9 | ||
|
|
fdb4806d2e | ||
|
|
2c8de07a8a | ||
|
|
b6e2bb88a8 | ||
|
|
2d60d55979 | ||
|
|
c29a5bc6ca | ||
|
|
a6f009ccd5 | ||
|
|
64d2af707a | ||
|
|
99e1c4b3ad | ||
|
|
2847d56f51 | ||
|
|
06c783d45f | ||
|
|
4f6bbee7b6 | ||
|
|
44816c55e9 | ||
|
|
b94aa5c360 | ||
|
|
4d0a33df75 | ||
|
|
0152f7a47a | ||
|
|
1c67601ae9 | ||
|
|
7c46951128 | ||
|
|
1108382429 | ||
|
|
473f8be395 | ||
|
|
2a9462598c | ||
|
|
f0ecf2161f | ||
|
|
96b69c7817 | ||
|
|
4332e482b5 | ||
|
|
2e19afbcc7 | ||
|
|
b0cd5a3ef7 | ||
|
|
364df54553 | ||
|
|
b0ae8203ad | ||
|
|
87cd4e6943 | ||
|
|
d31a6b4c5c | ||
|
|
f7fe9d14e1 | ||
|
|
65ac4dbf59 | ||
|
|
8a61c418d1 | ||
|
|
e0ca63b29a | ||
|
|
61de6c27f9 | ||
|
|
db9c33f62d | ||
|
|
c060834942 | ||
|
|
7747d6c305 | ||
|
|
ca881fd5b4 | ||
|
|
a4d05c1031 | ||
|
|
886fe1940b | ||
|
|
67ee799bed | ||
|
|
319b42119e | ||
|
|
0d794c4d29 | ||
|
|
2a7d07c88e | ||
|
|
a155e9640c | ||
|
|
5ba9dc365a |
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\ApcClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use `composer install --apcu-autoloader` instead.', \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* ApcClassLoader implements a wrapping autoloader cached in APC for PHP 5.3.
|
||||
*
|
||||
@@ -44,6 +46,8 @@ namespace Symfony\Component\ClassLoader;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use `composer install --apcu-autoloader` instead.
|
||||
*/
|
||||
class ApcClassLoader
|
||||
{
|
||||
@@ -57,8 +61,6 @@ class ApcClassLoader
|
||||
protected $decorated;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $prefix The APC namespace prefix to use
|
||||
* @param object $decorated A class loader object that implements the findFile() method
|
||||
*
|
||||
@@ -67,7 +69,7 @@ class ApcClassLoader
|
||||
*/
|
||||
public function __construct($prefix, $decorated)
|
||||
{
|
||||
if (!function_exists('apcu_fetch')) {
|
||||
if (!\function_exists('apcu_fetch')) {
|
||||
throw new \RuntimeException('Unable to use ApcClassLoader as APC is not installed.');
|
||||
}
|
||||
|
||||
@@ -86,7 +88,7 @@ class ApcClassLoader
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
spl_autoload_register([$this, 'loadClass'], true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +96,7 @@ class ApcClassLoader
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
spl_autoload_unregister([$this, 'loadClass']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,6 +113,8 @@ class ApcClassLoader
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,6 +140,6 @@ class ApcClassLoader
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return call_user_func_array(array($this->decorated, $method), $args);
|
||||
return \call_user_func_array([$this->decorated, $method], $args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
* deprecated the component: use Composer instead
|
||||
|
||||
3.0.0
|
||||
-----
|
||||
|
||||
|
||||
@@ -11,10 +11,16 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error('The '.__NAMESPACE__.'\ClassCollectionLoader class is deprecated since Symfony 3.3 and will be removed in 4.0.', \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* ClassCollectionLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
class ClassCollectionLoader
|
||||
{
|
||||
@@ -50,17 +56,17 @@ class ClassCollectionLoader
|
||||
$classes = array_diff($classes, $declared);
|
||||
|
||||
// the cache is different depending on which classes are already declared
|
||||
$name = $name.'-'.substr(hash('sha256', implode('|', $classes)), 0, 5);
|
||||
$name .= '-'.substr(hash('sha256', implode('|', $classes)), 0, 5);
|
||||
}
|
||||
|
||||
$classes = array_unique($classes);
|
||||
|
||||
// cache the core classes
|
||||
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));
|
||||
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s".', $cacheDir));
|
||||
}
|
||||
$cacheDir = rtrim(realpath($cacheDir), '/'.DIRECTORY_SEPARATOR);
|
||||
$cache = $cacheDir.DIRECTORY_SEPARATOR.$name.$extension;
|
||||
$cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/'.\DIRECTORY_SEPARATOR);
|
||||
$cache = $cacheDir.'/'.$name.$extension;
|
||||
|
||||
// auto-reload
|
||||
$reload = false;
|
||||
@@ -98,22 +104,62 @@ class ClassCollectionLoader
|
||||
$declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
|
||||
}
|
||||
|
||||
$c = '(?:\s*+(?:(?:#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
|
||||
$strictTypesRegex = str_replace('.', $c, "'^<\?php\s.declare.\(.strict_types.=.1.\).;'is");
|
||||
$files = self::inline($classes, $cache, $declared);
|
||||
|
||||
$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir);
|
||||
$files = array();
|
||||
if ($autoReload) {
|
||||
// save the resources
|
||||
self::writeCacheFile($metadata, serialize([array_values($files), $classes]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a file where classes and their parents are inlined.
|
||||
*
|
||||
* @param array $classes An array of classes to load
|
||||
* @param string $cache The file where classes are inlined
|
||||
* @param array $excluded An array of classes that won't be inlined
|
||||
*
|
||||
* @return array The source map of inlined classes, with classes as keys and files as values
|
||||
*
|
||||
* @throws \RuntimeException When class can't be loaded
|
||||
*/
|
||||
public static function inline($classes, $cache, array $excluded)
|
||||
{
|
||||
$declared = [];
|
||||
foreach (self::getOrderedClasses($excluded) as $class) {
|
||||
$declared[$class->getName()] = true;
|
||||
}
|
||||
|
||||
// cache the core classes
|
||||
$cacheDir = \dirname($cache);
|
||||
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));
|
||||
}
|
||||
|
||||
$spacesRegex = '(?:\s*+(?:(?:\#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
|
||||
$dontInlineRegex = <<<REGEX
|
||||
'(?:
|
||||
^<\?php\s.declare.\(.strict_types.=.1.\).;
|
||||
| \b__halt_compiler.\(.\)
|
||||
| \b__(?:DIR|FILE)__\b
|
||||
)'isx
|
||||
REGEX;
|
||||
$dontInlineRegex = str_replace('.', $spacesRegex, $dontInlineRegex);
|
||||
|
||||
$cacheDir = explode('/', str_replace(\DIRECTORY_SEPARATOR, '/', $cacheDir));
|
||||
$files = [];
|
||||
$content = '';
|
||||
foreach (self::getOrderedClasses($classes) as $class) {
|
||||
if (in_array($class->getName(), $declared)) {
|
||||
if (isset($declared[$class->getName()])) {
|
||||
continue;
|
||||
}
|
||||
$declared[$class->getName()] = true;
|
||||
|
||||
$files[] = $file = $class->getFileName();
|
||||
$files[$class->getName()] = $file = $class->getFileName();
|
||||
$c = file_get_contents($file);
|
||||
|
||||
if (preg_match($strictTypesRegex, $c)) {
|
||||
$file = explode(DIRECTORY_SEPARATOR, $file);
|
||||
if (preg_match($dontInlineRegex, $c)) {
|
||||
$file = explode('/', str_replace(\DIRECTORY_SEPARATOR, '/', $file));
|
||||
|
||||
for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) {
|
||||
if ($file[$i] !== $cacheDir[$i]) {
|
||||
@@ -121,16 +167,16 @@ class ClassCollectionLoader
|
||||
}
|
||||
}
|
||||
if (1 >= $i) {
|
||||
$file = var_export(implode(DIRECTORY_SEPARATOR, $file), true);
|
||||
$file = var_export(implode('/', $file), true);
|
||||
} else {
|
||||
$file = array_slice($file, $i);
|
||||
$file = str_repeat('..'.DIRECTORY_SEPARATOR, count($cacheDir) - $i).implode(DIRECTORY_SEPARATOR, $file);
|
||||
$file = '__DIR__.'.var_export(DIRECTORY_SEPARATOR.$file, true);
|
||||
$file = \array_slice($file, $i);
|
||||
$file = str_repeat('../', \count($cacheDir) - $i).implode('/', $file);
|
||||
$file = '__DIR__.'.var_export('/'.$file, true);
|
||||
}
|
||||
|
||||
$c = "\nnamespace {require $file;}";
|
||||
} else {
|
||||
$c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', $c);
|
||||
$c = preg_replace(['/^\s*<\?php/', '/\?>\s*$/'], '', $c);
|
||||
|
||||
// fakes namespace declaration for global code
|
||||
if (!$class->inNamespace()) {
|
||||
@@ -145,10 +191,7 @@ class ClassCollectionLoader
|
||||
}
|
||||
self::writeCacheFile($cache, '<?php '.$content);
|
||||
|
||||
if ($autoReload) {
|
||||
// save the resources
|
||||
self::writeCacheFile($metadata, serialize(array($files, $classes)));
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +203,7 @@ class ClassCollectionLoader
|
||||
*/
|
||||
public static function fixNamespaceDeclarations($source)
|
||||
{
|
||||
if (!function_exists('token_get_all') || !self::$useTokenizer) {
|
||||
if (!\function_exists('token_get_all') || !self::$useTokenizer) {
|
||||
if (preg_match('/(^|\s)namespace(.*?)\s*;/', $source)) {
|
||||
$source = preg_replace('/(^|\s)namespace(.*?)\s*;/', "$1namespace$2\n{", $source)."}\n";
|
||||
}
|
||||
@@ -173,21 +216,26 @@ class ClassCollectionLoader
|
||||
$inNamespace = false;
|
||||
$tokens = token_get_all($source);
|
||||
|
||||
$nsTokens = [\T_WHITESPACE => true, \T_NS_SEPARATOR => true, \T_STRING => true];
|
||||
if (\defined('T_NAME_QUALIFIED')) {
|
||||
$nsTokens[T_NAME_QUALIFIED] = true;
|
||||
}
|
||||
|
||||
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))) {
|
||||
} elseif (\in_array($token[0], [\T_COMMENT, \T_DOC_COMMENT])) {
|
||||
// strip comments
|
||||
continue;
|
||||
} elseif (T_NAMESPACE === $token[0]) {
|
||||
} elseif (\T_NAMESPACE === $token[0]) {
|
||||
if ($inNamespace) {
|
||||
$rawChunk .= "}\n";
|
||||
}
|
||||
$rawChunk .= $token[1];
|
||||
|
||||
// namespace name and whitespaces
|
||||
while (isset($tokens[++$i][1]) && in_array($tokens[$i][0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
|
||||
while (isset($tokens[++$i][1], $nsTokens[$tokens[$i][0]])) {
|
||||
$rawChunk .= $tokens[$i][1];
|
||||
}
|
||||
if ('{' === $tokens[$i]) {
|
||||
@@ -197,15 +245,15 @@ class ClassCollectionLoader
|
||||
$rawChunk = rtrim($rawChunk)."\n{";
|
||||
$inNamespace = true;
|
||||
}
|
||||
} elseif (T_START_HEREDOC === $token[0]) {
|
||||
} elseif (\T_START_HEREDOC === $token[0]) {
|
||||
$output .= self::compressCode($rawChunk).$token[1];
|
||||
do {
|
||||
$token = $tokens[++$i];
|
||||
$output .= isset($token[1]) && 'b"' !== $token ? $token[1] : $token;
|
||||
} while ($token[0] !== T_END_HEREDOC);
|
||||
} while (\T_END_HEREDOC !== $token[0]);
|
||||
$output .= "\n";
|
||||
$rawChunk = '';
|
||||
} elseif (T_CONSTANT_ENCAPSED_STRING === $token[0]) {
|
||||
} elseif (\T_CONSTANT_ENCAPSED_STRING === $token[0]) {
|
||||
$output .= self::compressCode($rawChunk).$token[1];
|
||||
$rawChunk = '';
|
||||
} else {
|
||||
@@ -219,7 +267,7 @@ class ClassCollectionLoader
|
||||
|
||||
$output .= self::compressCode($rawChunk);
|
||||
|
||||
if (PHP_VERSION_ID >= 70000) {
|
||||
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();
|
||||
@@ -246,8 +294,8 @@ class ClassCollectionLoader
|
||||
private static function compressCode($code)
|
||||
{
|
||||
return preg_replace(
|
||||
array('/^\s+/m', '/\s+$/m', '/([\n\r]+ *[\n\r]+)+/', '/[ \t]+/'),
|
||||
array('', '', "\n", ' '),
|
||||
['/^\s+/m', '/\s+$/m', '/([\n\r]+ *[\n\r]+)+/', '/[ \t]+/'],
|
||||
['', '', "\n", ' '],
|
||||
$code
|
||||
);
|
||||
}
|
||||
@@ -262,7 +310,13 @@ class ClassCollectionLoader
|
||||
*/
|
||||
private static function writeCacheFile($file, $content)
|
||||
{
|
||||
$tmpFile = tempnam(dirname($file), basename($file));
|
||||
$dir = \dirname($file);
|
||||
if (!is_writable($dir)) {
|
||||
throw new \RuntimeException(sprintf('Cache directory "%s" is not writable.', $dir));
|
||||
}
|
||||
|
||||
$tmpFile = tempnam($dir, basename($file));
|
||||
|
||||
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
|
||||
@chmod($file, 0666 & ~umask());
|
||||
|
||||
@@ -275,21 +329,19 @@ class ClassCollectionLoader
|
||||
/**
|
||||
* Gets an ordered array of passed classes including all their dependencies.
|
||||
*
|
||||
* @param array $classes
|
||||
*
|
||||
* @return \ReflectionClass[] An array of sorted \ReflectionClass instances (dependencies added if needed)
|
||||
*
|
||||
* @throws \InvalidArgumentException When a class can't be loaded
|
||||
*/
|
||||
private static function getOrderedClasses(array $classes)
|
||||
{
|
||||
$map = array();
|
||||
self::$seen = array();
|
||||
$map = [];
|
||||
self::$seen = [];
|
||||
foreach ($classes as $class) {
|
||||
try {
|
||||
$reflectionClass = new \ReflectionClass($class);
|
||||
} catch (\ReflectionException $e) {
|
||||
throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
|
||||
throw new \InvalidArgumentException(sprintf('Unable to load class "%s".', $class));
|
||||
}
|
||||
|
||||
$map = array_merge($map, self::getClassHierarchy($reflectionClass));
|
||||
@@ -301,12 +353,12 @@ class ClassCollectionLoader
|
||||
private static function getClassHierarchy(\ReflectionClass $class)
|
||||
{
|
||||
if (isset(self::$seen[$class->getName()])) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
self::$seen[$class->getName()] = true;
|
||||
|
||||
$classes = array($class);
|
||||
$classes = [$class];
|
||||
$parent = $class;
|
||||
while (($parent = $parent->getParentClass()) && $parent->isUserDefined() && !isset(self::$seen[$parent->getName()])) {
|
||||
self::$seen[$parent->getName()] = true;
|
||||
@@ -314,7 +366,7 @@ class ClassCollectionLoader
|
||||
array_unshift($classes, $parent);
|
||||
}
|
||||
|
||||
$traits = array();
|
||||
$traits = [];
|
||||
|
||||
foreach ($classes as $c) {
|
||||
foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
|
||||
@@ -329,7 +381,7 @@ class ClassCollectionLoader
|
||||
|
||||
private static function getInterfaces(\ReflectionClass $class)
|
||||
{
|
||||
$classes = array();
|
||||
$classes = [];
|
||||
|
||||
foreach ($class->getInterfaces() as $interface) {
|
||||
$classes = array_merge($classes, self::getInterfaces($interface));
|
||||
@@ -347,7 +399,7 @@ class ClassCollectionLoader
|
||||
private static function computeTraitDeps(\ReflectionClass $class)
|
||||
{
|
||||
$traits = $class->getTraits();
|
||||
$deps = array($class->getName() => $traits);
|
||||
$deps = [$class->getName() => $traits];
|
||||
while ($trait = array_pop($traits)) {
|
||||
if ($trait->isUserDefined() && !isset(self::$seen[$trait->getName()])) {
|
||||
self::$seen[$trait->getName()] = true;
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\ClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use Composer instead.', \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* ClassLoader implements an PSR-0 class loader.
|
||||
*
|
||||
@@ -36,11 +38,13 @@ namespace Symfony\Component\ClassLoader;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
private $prefixes = array();
|
||||
private $fallbackDirs = array();
|
||||
private $prefixes = [];
|
||||
private $fallbackDirs = [];
|
||||
private $useIncludePath = false;
|
||||
|
||||
/**
|
||||
@@ -91,12 +95,12 @@ class ClassLoader
|
||||
return;
|
||||
}
|
||||
if (isset($this->prefixes[$prefix])) {
|
||||
if (is_array($paths)) {
|
||||
if (\is_array($paths)) {
|
||||
$this->prefixes[$prefix] = array_unique(array_merge(
|
||||
$this->prefixes[$prefix],
|
||||
$paths
|
||||
));
|
||||
} elseif (!in_array($paths, $this->prefixes[$prefix])) {
|
||||
} elseif (!\in_array($paths, $this->prefixes[$prefix])) {
|
||||
$this->prefixes[$prefix][] = $paths;
|
||||
}
|
||||
} else {
|
||||
@@ -132,7 +136,7 @@ class ClassLoader
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
spl_autoload_register([$this, 'loadClass'], true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +144,7 @@ class ClassLoader
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
spl_autoload_unregister([$this, 'loadClass']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,6 +161,8 @@ class ClassLoader
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +176,7 @@ class ClassLoader
|
||||
{
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)).DIRECTORY_SEPARATOR;
|
||||
$classPath = str_replace('\\', \DIRECTORY_SEPARATOR, substr($class, 0, $pos)).\DIRECTORY_SEPARATOR;
|
||||
$className = substr($class, $pos + 1);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
@@ -178,26 +184,28 @@ class ClassLoader
|
||||
$className = $class;
|
||||
}
|
||||
|
||||
$classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
|
||||
$classPath .= str_replace('_', \DIRECTORY_SEPARATOR, $className).'.php';
|
||||
|
||||
foreach ($this->prefixes as $prefix => $dirs) {
|
||||
if ($class === strstr($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
|
||||
return $dir.DIRECTORY_SEPARATOR.$classPath;
|
||||
if (file_exists($dir.\DIRECTORY_SEPARATOR.$classPath)) {
|
||||
return $dir.\DIRECTORY_SEPARATOR.$classPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->fallbackDirs as $dir) {
|
||||
if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
|
||||
return $dir.DIRECTORY_SEPARATOR.$classPath;
|
||||
if (file_exists($dir.\DIRECTORY_SEPARATOR.$classPath)) {
|
||||
return $dir.\DIRECTORY_SEPARATOR.$classPath;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,14 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\ClassMapGenerator class is deprecated since Symfony 3.3 and will be removed in 4.0. Use Composer instead.', \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* ClassMapGenerator.
|
||||
*
|
||||
* @author Gyula Sallai <salla016@gmail.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
class ClassMapGenerator
|
||||
{
|
||||
@@ -27,7 +31,7 @@ class ClassMapGenerator
|
||||
public static function dump($dirs, $file)
|
||||
{
|
||||
$dirs = (array) $dirs;
|
||||
$maps = array();
|
||||
$maps = [];
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
$maps = array_merge($maps, static::createMap($dir));
|
||||
@@ -45,26 +49,26 @@ class ClassMapGenerator
|
||||
*/
|
||||
public static function createMap($dir)
|
||||
{
|
||||
if (is_string($dir)) {
|
||||
if (\is_string($dir)) {
|
||||
$dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
|
||||
}
|
||||
|
||||
$map = array();
|
||||
$map = [];
|
||||
|
||||
foreach ($dir as $file) {
|
||||
if (!$file->isFile()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $file->getRealPath();
|
||||
$path = $file->getRealPath() ?: $file->getPathname();
|
||||
|
||||
if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') {
|
||||
if ('php' !== pathinfo($path, \PATHINFO_EXTENSION)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classes = self::findClasses($path);
|
||||
|
||||
if (PHP_VERSION_ID >= 70000) {
|
||||
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();
|
||||
}
|
||||
@@ -89,7 +93,12 @@ class ClassMapGenerator
|
||||
$contents = file_get_contents($path);
|
||||
$tokens = token_get_all($contents);
|
||||
|
||||
$classes = array();
|
||||
$nsTokens = [\T_STRING => true, \T_NS_SEPARATOR => true];
|
||||
if (\defined('T_NAME_QUALIFIED')) {
|
||||
$nsTokens[T_NAME_QUALIFIED] = true;
|
||||
}
|
||||
|
||||
$classes = [];
|
||||
|
||||
$namespace = '';
|
||||
for ($i = 0; isset($tokens[$i]); ++$i) {
|
||||
@@ -102,19 +111,19 @@ class ClassMapGenerator
|
||||
$class = '';
|
||||
|
||||
switch ($token[0]) {
|
||||
case T_NAMESPACE:
|
||||
case \T_NAMESPACE:
|
||||
$namespace = '';
|
||||
// If there is a namespace, extract it
|
||||
while (isset($tokens[++$i][1])) {
|
||||
if (in_array($tokens[$i][0], array(T_STRING, T_NS_SEPARATOR))) {
|
||||
if (isset($nsTokens[$tokens[$i][0]])) {
|
||||
$namespace .= $tokens[$i][1];
|
||||
}
|
||||
}
|
||||
$namespace .= '\\';
|
||||
break;
|
||||
case T_CLASS:
|
||||
case T_INTERFACE:
|
||||
case T_TRAIT:
|
||||
case \T_CLASS:
|
||||
case \T_INTERFACE:
|
||||
case \T_TRAIT:
|
||||
// Skip usage of ::class constant
|
||||
$isClassConstant = false;
|
||||
for ($j = $i - 1; $j > 0; --$j) {
|
||||
@@ -122,10 +131,10 @@ class ClassMapGenerator
|
||||
break;
|
||||
}
|
||||
|
||||
if (T_DOUBLE_COLON === $tokens[$j][0]) {
|
||||
if (\T_DOUBLE_COLON === $tokens[$j][0]) {
|
||||
$isClassConstant = true;
|
||||
break;
|
||||
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
|
||||
} elseif (!\in_array($tokens[$j][0], [\T_WHITESPACE, \T_DOC_COMMENT, \T_COMMENT])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -137,9 +146,9 @@ class ClassMapGenerator
|
||||
// Find the classname
|
||||
while (isset($tokens[++$i][1])) {
|
||||
$t = $tokens[$i];
|
||||
if (T_STRING === $t[0]) {
|
||||
if (\T_STRING === $t[0]) {
|
||||
$class .= $t[1];
|
||||
} elseif ('' !== $class && T_WHITESPACE === $t[0]) {
|
||||
} elseif ('' !== $class && \T_WHITESPACE === $t[0]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2004-2016 Fabien Potencier
|
||||
Copyright (c) 2004-2020 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
|
||||
|
||||
@@ -11,18 +11,20 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\MapClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use Composer instead.', \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* A class loader that uses a mapping file to look up paths.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
class MapClassLoader
|
||||
{
|
||||
private $map = array();
|
||||
private $map = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $map A map where keys are classes and values the absolute file path
|
||||
*/
|
||||
public function __construct(array $map)
|
||||
@@ -37,7 +39,7 @@ class MapClassLoader
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
spl_autoload_register([$this, 'loadClass'], true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +63,6 @@ class MapClassLoader
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
if (isset($this->map[$class])) {
|
||||
return $this->map[$class];
|
||||
}
|
||||
return isset($this->map[$class]) ? $this->map[$class] : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,20 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\Psr4ClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use Composer instead.', \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* A PSR-4 compatible class loader.
|
||||
*
|
||||
* See http://www.php-fig.org/psr/psr-4/
|
||||
*
|
||||
* @author Alexander M. Turek <me@derrabus.de>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
class Psr4ClassLoader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $prefixes = array();
|
||||
private $prefixes = [];
|
||||
|
||||
/**
|
||||
* @param string $prefix
|
||||
@@ -32,8 +33,8 @@ class Psr4ClassLoader
|
||||
public function addPrefix($prefix, $baseDir)
|
||||
{
|
||||
$prefix = trim($prefix, '\\').'\\';
|
||||
$baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
|
||||
$this->prefixes[] = array($prefix, $baseDir);
|
||||
$baseDir = rtrim($baseDir, \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR;
|
||||
$this->prefixes[] = [$prefix, $baseDir];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,13 +48,15 @@ class Psr4ClassLoader
|
||||
|
||||
foreach ($this->prefixes as list($currentPrefix, $currentBaseDir)) {
|
||||
if (0 === strpos($class, $currentPrefix)) {
|
||||
$classWithoutPrefix = substr($class, strlen($currentPrefix));
|
||||
$file = $currentBaseDir.str_replace('\\', DIRECTORY_SEPARATOR, $classWithoutPrefix).'.php';
|
||||
$classWithoutPrefix = substr($class, \strlen($currentPrefix));
|
||||
$file = $currentBaseDir.str_replace('\\', \DIRECTORY_SEPARATOR, $classWithoutPrefix).'.php';
|
||||
if (file_exists($file)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +83,7 @@ class Psr4ClassLoader
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
spl_autoload_register([$this, 'loadClass'], true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +91,6 @@ class Psr4ClassLoader
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
spl_autoload_unregister([$this, 'loadClass']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ their locations for performance.
|
||||
Resources
|
||||
---------
|
||||
|
||||
* [Documentation](https://symfony.com/doc/current/components/class_loader/index.html)
|
||||
* [Documentation](https://symfony.com/doc/current/components/class_loader.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)
|
||||
|
||||
@@ -11,14 +11,18 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\ApcClassLoader;
|
||||
use Symfony\Component\ClassLoader\ClassLoader;
|
||||
|
||||
class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ApcClassLoaderTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!(ini_get('apc.enabled') && ini_get('apc.enable_cli'))) {
|
||||
if (!(filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN) && filter_var(ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOLEAN))) {
|
||||
$this->markTestSkipped('The apc extension is not enabled.');
|
||||
} else {
|
||||
apcu_clear_cache();
|
||||
@@ -27,7 +31,7 @@ class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (ini_get('apc.enabled') && ini_get('apc.enable_cli')) {
|
||||
if (filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN) && filter_var(ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOLEAN)) {
|
||||
apcu_clear_cache();
|
||||
}
|
||||
}
|
||||
@@ -35,7 +39,7 @@ class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Apc\Namespaced', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
|
||||
$loader = new ApcClassLoader('test.prefix.', $loader);
|
||||
|
||||
@@ -48,8 +52,8 @@ class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
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->addPrefix('Apc\Namespaced', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Apc_Pearlike_', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
|
||||
$loader = new ApcClassLoader('test.prefix.', $loader);
|
||||
$loader->loadClass($testClassName);
|
||||
@@ -58,10 +62,10 @@ class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
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'),
|
||||
);
|
||||
return [
|
||||
['\\Apc\\Namespaced\\Foo', 'Apc\\Namespaced\\Foo', '->loadClass() loads Apc\Namespaced\Foo class'],
|
||||
['Apc_Pearlike_Foo', 'Apc_Pearlike_Foo', '->loadClass() loads Apc_Pearlike_Foo class'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,9 +74,9 @@ class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
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->addPrefix('Apc\Namespaced', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Apc_Pearlike_', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('', [__DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/fallback']);
|
||||
|
||||
$loader = new ApcClassLoader('test.prefix.fallback', $loader);
|
||||
$loader->loadClass($testClassName);
|
||||
@@ -82,12 +86,12 @@ class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
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_Pearlike_FooBar', 'Apc_Pearlike_FooBar', '->loadClass() loads Apc_Pearlike_Baz class from fallback dir'),
|
||||
);
|
||||
return [
|
||||
['\\Apc\\Namespaced\\Baz', 'Apc\\Namespaced\\Baz', '->loadClass() loads Apc\Namespaced\Baz class'],
|
||||
['Apc_Pearlike_Baz', 'Apc_Pearlike_Baz', '->loadClass() loads Apc_Pearlike_Baz class'],
|
||||
['\\Apc\\Namespaced\\FooBar', 'Apc\\Namespaced\\FooBar', '->loadClass() loads Apc\Namespaced\Baz class from fallback dir'],
|
||||
['Apc_Pearlike_FooBar', 'Apc_Pearlike_FooBar', '->loadClass() loads Apc_Pearlike_Baz class from fallback dir'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,40 +110,40 @@ class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
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',
|
||||
),
|
||||
return [
|
||||
[
|
||||
[
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
],
|
||||
'Apc\NamespaceCollision\A\Foo',
|
||||
'->loadClass() loads NamespaceCollision\A\Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
],
|
||||
'Apc\NamespaceCollision\A\Bar',
|
||||
'->loadClass() loads NamespaceCollision\A\Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
],
|
||||
'Apc\NamespaceCollision\A\B\Foo',
|
||||
'->loadClass() loads NamespaceCollision\A\B\Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
],
|
||||
'Apc\NamespaceCollision\A\B\Bar',
|
||||
'->loadClass() loads NamespaceCollision\A\B\Bar from beta.',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,39 +162,39 @@ class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function getLoadClassPrefixCollisionTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
),
|
||||
return [
|
||||
[
|
||||
[
|
||||
'ApcPrefixCollision_A_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
],
|
||||
'ApcPrefixCollision_A_Foo',
|
||||
'->loadClass() loads ApcPrefixCollision_A_Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
'ApcPrefixCollision_A_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
],
|
||||
'ApcPrefixCollision_A_Bar',
|
||||
'->loadClass() loads ApcPrefixCollision_A_Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'ApcPrefixCollision_A_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
],
|
||||
'ApcPrefixCollision_A_B_Foo',
|
||||
'->loadClass() loads ApcPrefixCollision_A_B_Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
'ApcPrefixCollision_A_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
],
|
||||
'ApcPrefixCollision_A_B_Bar',
|
||||
'->loadClass() loads ApcPrefixCollision_A_B_Bar from beta.',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,20 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\ClassCollectionLoader;
|
||||
use Symfony\Component\ClassLoader\Tests\Fixtures\DeclaredClass;
|
||||
use Symfony\Component\ClassLoader\Tests\Fixtures\WarmedClass;
|
||||
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/GInterface.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/CInterface.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/B.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/A.php';
|
||||
|
||||
class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ClassCollectionLoaderTest extends TestCase
|
||||
{
|
||||
public function testTraitDependencies()
|
||||
{
|
||||
@@ -28,17 +34,17 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$ordered = $m->invoke(null, array('CTFoo'));
|
||||
$ordered = $m->invoke(null, ['CTFoo']);
|
||||
|
||||
$this->assertEquals(
|
||||
array('TD', 'TC', 'TB', 'TA', 'TZ', 'CTFoo'),
|
||||
['TD', 'TC', 'TB', 'TA', 'TZ', 'CTFoo'],
|
||||
array_map(function ($class) { return $class->getName(); }, $ordered)
|
||||
);
|
||||
|
||||
$ordered = $m->invoke(null, array('CTBar'));
|
||||
$ordered = $m->invoke(null, ['CTBar']);
|
||||
|
||||
$this->assertEquals(
|
||||
array('TD', 'TZ', 'TC', 'TB', 'TA', 'CTBar'),
|
||||
['TD', 'TZ', 'TC', 'TB', 'TA', 'CTBar'],
|
||||
array_map(function ($class) { return $class->getName(); }, $ordered)
|
||||
);
|
||||
}
|
||||
@@ -48,12 +54,12 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testClassReordering(array $classes)
|
||||
{
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'ClassesWithParents\\GInterface',
|
||||
'ClassesWithParents\\CInterface',
|
||||
'ClassesWithParents\\B',
|
||||
'ClassesWithParents\\A',
|
||||
);
|
||||
];
|
||||
|
||||
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
@@ -66,27 +72,27 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function getDifferentOrders()
|
||||
{
|
||||
return array(
|
||||
array(array(
|
||||
return [
|
||||
[[
|
||||
'ClassesWithParents\\A',
|
||||
'ClassesWithParents\\CInterface',
|
||||
'ClassesWithParents\\GInterface',
|
||||
'ClassesWithParents\\B',
|
||||
)),
|
||||
array(array(
|
||||
]],
|
||||
[[
|
||||
'ClassesWithParents\\B',
|
||||
'ClassesWithParents\\A',
|
||||
'ClassesWithParents\\CInterface',
|
||||
)),
|
||||
array(array(
|
||||
]],
|
||||
[[
|
||||
'ClassesWithParents\\CInterface',
|
||||
'ClassesWithParents\\B',
|
||||
'ClassesWithParents\\A',
|
||||
)),
|
||||
array(array(
|
||||
]],
|
||||
[[
|
||||
'ClassesWithParents\\A',
|
||||
)),
|
||||
);
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +106,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/D.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/E.php';
|
||||
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'ClassesWithParents\\GInterface',
|
||||
'ClassesWithParents\\CInterface',
|
||||
'ClassesWithParents\\ATrait',
|
||||
@@ -110,7 +116,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
'ClassesWithParents\\A',
|
||||
'ClassesWithParents\\D',
|
||||
'ClassesWithParents\\E',
|
||||
);
|
||||
];
|
||||
|
||||
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
@@ -123,15 +129,15 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function getDifferentOrdersForTraits()
|
||||
{
|
||||
return array(
|
||||
array(array(
|
||||
return [
|
||||
[[
|
||||
'ClassesWithParents\\E',
|
||||
'ClassesWithParents\\ATrait',
|
||||
)),
|
||||
array(array(
|
||||
]],
|
||||
[[
|
||||
'ClassesWithParents\\E',
|
||||
)),
|
||||
);
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
public function testFixClassWithTraitsOrdering()
|
||||
@@ -140,16 +146,16 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/F.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/G.php';
|
||||
|
||||
$classes = array(
|
||||
$classes = [
|
||||
'ClassesWithParents\\F',
|
||||
'ClassesWithParents\\G',
|
||||
);
|
||||
];
|
||||
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'ClassesWithParents\\CTrait',
|
||||
'ClassesWithParents\\F',
|
||||
'ClassesWithParents\\G',
|
||||
);
|
||||
];
|
||||
|
||||
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
@@ -170,14 +176,14 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function getFixNamespaceDeclarationsData()
|
||||
{
|
||||
return array(
|
||||
array("namespace;\nclass Foo {}\n", "namespace\n{\nclass Foo {}\n}"),
|
||||
array("namespace Foo;\nclass Foo {}\n", "namespace Foo\n{\nclass Foo {}\n}"),
|
||||
array("namespace Bar ;\nclass Foo {}\n", "namespace Bar\n{\nclass Foo {}\n}"),
|
||||
array("namespace Foo\Bar;\nclass Foo {}\n", "namespace Foo\Bar\n{\nclass Foo {}\n}"),
|
||||
array("namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n", "namespace Foo\Bar\Bar\n{\nclass Foo {}\n}"),
|
||||
array("namespace\n{\nclass Foo {}\n}\n", "namespace\n{\nclass Foo {}\n}"),
|
||||
);
|
||||
return [
|
||||
["namespace;\nclass Foo {}\n", "namespace\n{\nclass Foo {}\n}"],
|
||||
["namespace Foo;\nclass Foo {}\n", "namespace Foo\n{\nclass Foo {}\n}"],
|
||||
["namespace Bar ;\nclass Foo {}\n", "namespace Bar\n{\nclass Foo {}\n}"],
|
||||
["namespace Foo\Bar;\nclass Foo {}\n", "namespace Foo\Bar\n{\nclass Foo {}\n}"],
|
||||
["namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n", "namespace Foo\Bar\Bar\n{\nclass Foo {}\n}"],
|
||||
["namespace\n{\nclass Foo {}\n}\n", "namespace\n{\nclass Foo {}\n}"],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,26 +198,24 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function getFixNamespaceDeclarationsDataWithoutTokenizer()
|
||||
{
|
||||
return array(
|
||||
array("namespace;\nclass Foo {}\n", "namespace\n{\nclass Foo {}\n}\n"),
|
||||
array("namespace Foo;\nclass Foo {}\n", "namespace Foo\n{\nclass Foo {}\n}\n"),
|
||||
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("\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n", "\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n"),
|
||||
);
|
||||
return [
|
||||
["namespace;\nclass Foo {}\n", "namespace\n{\nclass Foo {}\n}\n"],
|
||||
["namespace Foo;\nclass Foo {}\n", "namespace Foo\n{\nclass Foo {}\n}\n"],
|
||||
["namespace Bar ;\nclass Foo {}\n", "namespace Bar\n{\nclass Foo {}\n}\n"],
|
||||
["namespace Foo\Bar;\nclass Foo {}\n", "namespace Foo\Bar\n{\nclass Foo {}\n}\n"],
|
||||
["namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n", "namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n"],
|
||||
["\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n", "\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n"],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testUnableToLoadClassException()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
if (is_file($file = sys_get_temp_dir().'/foo.php')) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
ClassCollectionLoader::load(array('SomeNotExistingClass'), sys_get_temp_dir(), 'foo', false);
|
||||
ClassCollectionLoader::load(['SomeNotExistingClass'], sys_get_temp_dir(), 'foo', false);
|
||||
}
|
||||
|
||||
public function testCommentStripping()
|
||||
@@ -221,14 +225,14 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
spl_autoload_register($r = function ($class) {
|
||||
if (0 === strpos($class, 'Namespaced') || 0 === strpos($class, 'Pearlike_')) {
|
||||
@require_once __DIR__.'/Fixtures/'.str_replace(array('\\', '_'), '/', $class).'.php';
|
||||
@require_once __DIR__.'/Fixtures/'.str_replace(['\\', '_'], '/', $class).'.php';
|
||||
}
|
||||
});
|
||||
|
||||
$strictTypes = defined('HHVM_VERSION') ? '' : "\nnamespace {require __DIR__.'/Fixtures/Namespaced/WithStrictTypes.php';}";
|
||||
$strictTypes = \defined('HHVM_VERSION') ? '' : "\nnamespace {require __DIR__.'/Fixtures/Namespaced/WithStrictTypes.php';}";
|
||||
|
||||
ClassCollectionLoader::load(
|
||||
array('Namespaced\\WithComments', 'Pearlike_WithComments', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
|
||||
['Namespaced\\WithComments', 'Pearlike_WithComments', 'Namespaced\\WithDirMagic', 'Namespaced\\WithFileMagic', 'Namespaced\\WithHaltCompiler', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'],
|
||||
__DIR__,
|
||||
'bar',
|
||||
false
|
||||
@@ -268,11 +272,46 @@ class Pearlike_WithComments
|
||||
public static $loaded = true;
|
||||
}
|
||||
}
|
||||
namespace {require __DIR__.'/Fixtures/Namespaced/WithDirMagic.php';}
|
||||
namespace {require __DIR__.'/Fixtures/Namespaced/WithFileMagic.php';}
|
||||
namespace {require __DIR__.'/Fixtures/Namespaced/WithHaltCompiler.php';}
|
||||
EOF
|
||||
.$strictTypes,
|
||||
str_replace(array("<?php \n", '\\\\'), array('', '/'), file_get_contents($file))
|
||||
str_replace(["<?php \n", '\\\\'], ['', '/'], file_get_contents($file))
|
||||
);
|
||||
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
public function testInline()
|
||||
{
|
||||
$this->assertTrue(class_exists(WarmedClass::class, true));
|
||||
|
||||
@unlink($cache = sys_get_temp_dir().'/inline.php');
|
||||
|
||||
$classes = [WarmedClass::class];
|
||||
$excluded = [DeclaredClass::class];
|
||||
|
||||
ClassCollectionLoader::inline($classes, $cache, $excluded);
|
||||
|
||||
$this->assertSame(<<<'EOTXT'
|
||||
<?php
|
||||
namespace Symfony\Component\ClassLoader\Tests\Fixtures
|
||||
{
|
||||
interface WarmedInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
namespace Symfony\Component\ClassLoader\Tests\Fixtures
|
||||
{
|
||||
class WarmedClass extends DeclaredClass implements WarmedInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
EOTXT
|
||||
, file_get_contents($cache)
|
||||
);
|
||||
|
||||
unlink($cache);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,20 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\ClassLoader;
|
||||
|
||||
class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ClassLoaderTest extends TestCase
|
||||
{
|
||||
public function testGetPrefixes()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Bar', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Bas', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Foo', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Bar', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Bas', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$prefixes = $loader->getPrefixes();
|
||||
$this->assertArrayHasKey('Foo', $prefixes);
|
||||
$this->assertArrayNotHasKey('Foo1', $prefixes);
|
||||
@@ -31,8 +35,8 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetFallbackDirs()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix(null, __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix(null, __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix(null, __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix(null, __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$fallback_dirs = $loader->getFallbackDirs();
|
||||
$this->assertCount(2, $fallback_dirs);
|
||||
}
|
||||
@@ -43,18 +47,18 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadClass($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Namespaced2\\', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Pearlike2_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Namespaced2\\', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Pearlike2_', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Namespaced2\\Foo', 'Namespaced2\\Foo', '->loadClass() loads Namespaced2\Foo class'),
|
||||
array('\\Pearlike2_Foo', 'Pearlike2_Foo', '->loadClass() loads Pearlike2_Foo class'),
|
||||
);
|
||||
return [
|
||||
['\\Namespaced2\\Foo', 'Namespaced2\\Foo', '->loadClass() loads Namespaced2\Foo class'],
|
||||
['\\Pearlike2_Foo', 'Pearlike2_Foo', '->loadClass() loads Pearlike2_Foo class'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,24 +67,24 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadNonexistentClass($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Namespaced2\\', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Pearlike2_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Namespaced2\\', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Pearlike2_', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertFalse(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadNonexistentClassTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Pearlike3_Bar', '\\Pearlike3_Bar', '->loadClass() loads non existing Pearlike3_Bar class with a leading slash'),
|
||||
);
|
||||
return [
|
||||
['\\Pearlike3_Bar', '\\Pearlike3_Bar', '->loadClass() loads non existing Pearlike3_Bar class with a leading slash'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testAddPrefixSingle()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$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']);
|
||||
@@ -89,8 +93,8 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testAddPrefixesSingle()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefixes(array('Foo' => array('foo', 'foo')));
|
||||
$loader->addPrefixes(array('Foo' => array('foo')));
|
||||
$loader->addPrefixes(['Foo' => ['foo', 'foo']]);
|
||||
$loader->addPrefixes(['Foo' => ['foo']]);
|
||||
$prefixes = $loader->getPrefixes();
|
||||
$this->assertArrayHasKey('Foo', $prefixes);
|
||||
$this->assertCount(1, $prefixes['Foo'], print_r($prefixes, true));
|
||||
@@ -120,9 +124,9 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader->setUseIncludePath(true);
|
||||
$this->assertTrue($loader->getUseIncludePath());
|
||||
|
||||
set_include_path(__DIR__.'/Fixtures/includepath'.PATH_SEPARATOR.$includePath);
|
||||
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'));
|
||||
$this->assertEquals(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'includepath'.\DIRECTORY_SEPARATOR.'Foo.php', $loader->findFile('Foo'));
|
||||
|
||||
set_include_path($includePath);
|
||||
}
|
||||
@@ -133,21 +137,21 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadClassFromFallback($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Namespaced2\\', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Pearlike2_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('', array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'));
|
||||
$loader->addPrefix('Namespaced2\\', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Pearlike2_', __DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('', [__DIR__.\DIRECTORY_SEPARATOR.'Fixtures/fallback']);
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassFromFallbackTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Namespaced2\\Baz', 'Namespaced2\\Baz', '->loadClass() loads Namespaced2\Baz class'),
|
||||
array('\\Pearlike2_Baz', 'Pearlike2_Baz', '->loadClass() loads Pearlike2_Baz class'),
|
||||
array('\\Namespaced2\\FooBar', 'Namespaced2\\FooBar', '->loadClass() loads Namespaced2\Baz class from fallback dir'),
|
||||
array('\\Pearlike2_FooBar', 'Pearlike2_FooBar', '->loadClass() loads Pearlike2_Baz class from fallback dir'),
|
||||
);
|
||||
return [
|
||||
['\\Namespaced2\\Baz', 'Namespaced2\\Baz', '->loadClass() loads Namespaced2\Baz class'],
|
||||
['\\Pearlike2_Baz', 'Pearlike2_Baz', '->loadClass() loads Pearlike2_Baz class'],
|
||||
['\\Namespaced2\\FooBar', 'Namespaced2\\FooBar', '->loadClass() loads Namespaced2\Baz class from fallback dir'],
|
||||
['\\Pearlike2_FooBar', 'Pearlike2_FooBar', '->loadClass() loads Pearlike2_Baz class from fallback dir'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,71 +168,71 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function getLoadClassNamespaceCollisionTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\C' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'NamespaceCollision\\C\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
return [
|
||||
[
|
||||
[
|
||||
'NamespaceCollision\\C' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'NamespaceCollision\\C\\B' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
],
|
||||
'NamespaceCollision\C\Foo',
|
||||
'->loadClass() loads NamespaceCollision\C\Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\C\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'NamespaceCollision\\C' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'NamespaceCollision\\C\\B' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'NamespaceCollision\\C' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
],
|
||||
'NamespaceCollision\C\Bar',
|
||||
'->loadClass() loads NamespaceCollision\C\Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\C' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'NamespaceCollision\\C\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'NamespaceCollision\\C' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'NamespaceCollision\\C\\B' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
],
|
||||
'NamespaceCollision\C\B\Foo',
|
||||
'->loadClass() loads NamespaceCollision\C\B\Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\C\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'NamespaceCollision\\C' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'NamespaceCollision\\C\\B' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'NamespaceCollision\\C' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
],
|
||||
'NamespaceCollision\C\B\Bar',
|
||||
'->loadClass() loads NamespaceCollision\C\B\Bar from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_C_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'PrefixCollision_C_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'PrefixCollision_C_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'PrefixCollision_C_B_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
],
|
||||
'PrefixCollision_C_Foo',
|
||||
'->loadClass() loads PrefixCollision_C_Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_C_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'PrefixCollision_C_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'PrefixCollision_C_B_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'PrefixCollision_C_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
],
|
||||
'PrefixCollision_C_Bar',
|
||||
'->loadClass() loads PrefixCollision_C_Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_C_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'PrefixCollision_C_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'PrefixCollision_C_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'PrefixCollision_C_B_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
],
|
||||
'PrefixCollision_C_B_Foo',
|
||||
'->loadClass() loads PrefixCollision_C_B_Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_C_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'PrefixCollision_C_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
],
|
||||
[
|
||||
[
|
||||
'PrefixCollision_C_B_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'PrefixCollision_C_' => __DIR__.\DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
],
|
||||
'PrefixCollision_C_B_Bar',
|
||||
'->loadClass() loads PrefixCollision_C_B_Bar from beta.',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
||||
|
||||
class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ClassMapGeneratorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var string|null
|
||||
@@ -70,28 +74,30 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function getTestCreateMapTests()
|
||||
{
|
||||
$data = array(
|
||||
array(__DIR__.'/Fixtures/Namespaced', array(
|
||||
$data = [
|
||||
[__DIR__.'/Fixtures/Namespaced', [
|
||||
'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',
|
||||
'Namespaced\WithStrictTypes' => realpath(__DIR__).'/Fixtures/Namespaced/WithStrictTypes.php',
|
||||
),
|
||||
),
|
||||
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array(
|
||||
'Namespaced\\WithStrictTypes' => realpath(__DIR__).'/Fixtures/Namespaced/WithStrictTypes.php',
|
||||
'Namespaced\\WithHaltCompiler' => realpath(__DIR__).'/Fixtures/Namespaced/WithHaltCompiler.php',
|
||||
'Namespaced\\WithDirMagic' => realpath(__DIR__).'/Fixtures/Namespaced/WithDirMagic.php',
|
||||
'Namespaced\\WithFileMagic' => realpath(__DIR__).'/Fixtures/Namespaced/WithFileMagic.php',
|
||||
]],
|
||||
[__DIR__.'/Fixtures/beta/NamespaceCollision', [
|
||||
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
|
||||
'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Foo.php',
|
||||
'NamespaceCollision\\C\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Bar.php',
|
||||
'NamespaceCollision\\C\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Foo.php',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/Pearlike', array(
|
||||
]],
|
||||
[__DIR__.'/Fixtures/Pearlike', [
|
||||
'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(
|
||||
]],
|
||||
[__DIR__.'/Fixtures/classmap', [
|
||||
'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',
|
||||
@@ -102,19 +108,19 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php',
|
||||
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
|
||||
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/php5.4', array(
|
||||
]],
|
||||
[__DIR__.'/Fixtures/php5.4', [
|
||||
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\IBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TFooBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/php5.5', array(
|
||||
]],
|
||||
[__DIR__.'/Fixtures/php5.5', [
|
||||
'ClassCons\\Foo' => __DIR__.'/Fixtures/php5.5/class_cons.php',
|
||||
)),
|
||||
);
|
||||
]],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -124,15 +130,15 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
$finder = new \Symfony\Component\Finder\Finder();
|
||||
$finder->files()->in(__DIR__.'/Fixtures/beta/NamespaceCollision');
|
||||
|
||||
$this->assertEqualsNormalized(array(
|
||||
$this->assertEqualsNormalized([
|
||||
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
|
||||
'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Foo.php',
|
||||
'NamespaceCollision\\C\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Bar.php',
|
||||
'NamespaceCollision\\C\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Foo.php',
|
||||
), ClassMapGenerator::createMap($finder));
|
||||
], ClassMapGenerator::createMap($finder));
|
||||
}
|
||||
|
||||
protected function assertEqualsNormalized($expected, $actual, $message = null)
|
||||
protected function assertEqualsNormalized($expected, $actual, $message = '')
|
||||
{
|
||||
foreach ($expected as $ns => $path) {
|
||||
$expected[$ns] = str_replace('\\', '/', $path);
|
||||
|
||||
7
Tests/Fixtures/DeclaredClass.php
Normal file
7
Tests/Fixtures/DeclaredClass.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests\Fixtures;
|
||||
|
||||
class DeclaredClass implements DeclaredInterface
|
||||
{
|
||||
}
|
||||
7
Tests/Fixtures/DeclaredInterface.php
Normal file
7
Tests/Fixtures/DeclaredInterface.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests\Fixtures;
|
||||
|
||||
interface DeclaredInterface
|
||||
{
|
||||
}
|
||||
15
Tests/Fixtures/Namespaced/WithDirMagic.php
Normal file
15
Tests/Fixtures/Namespaced/WithDirMagic.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* foo
|
||||
*/
|
||||
|
||||
namespace Namespaced;
|
||||
|
||||
class WithDirMagic
|
||||
{
|
||||
public function getDir()
|
||||
{
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
15
Tests/Fixtures/Namespaced/WithFileMagic.php
Normal file
15
Tests/Fixtures/Namespaced/WithFileMagic.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* foo
|
||||
*/
|
||||
|
||||
namespace Namespaced;
|
||||
|
||||
class WithFileMagic
|
||||
{
|
||||
public function getFile()
|
||||
{
|
||||
return __FILE__;
|
||||
}
|
||||
}
|
||||
18
Tests/Fixtures/Namespaced/WithHaltCompiler.php
Normal file
18
Tests/Fixtures/Namespaced/WithHaltCompiler.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* foo
|
||||
*/
|
||||
|
||||
namespace Namespaced;
|
||||
|
||||
class WithHaltCompiler
|
||||
{
|
||||
}
|
||||
|
||||
// the end of the script execution
|
||||
__halt_compiler(); data
|
||||
data
|
||||
data
|
||||
data
|
||||
...
|
||||
@@ -4,7 +4,7 @@
|
||||
* foo
|
||||
*/
|
||||
|
||||
declare (strict_types = 1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Namespaced;
|
||||
|
||||
|
||||
7
Tests/Fixtures/WarmedClass.php
Normal file
7
Tests/Fixtures/WarmedClass.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests\Fixtures;
|
||||
|
||||
class WarmedClass extends DeclaredClass implements WarmedInterface
|
||||
{
|
||||
}
|
||||
7
Tests/Fixtures/WarmedInterface.php
Normal file
7
Tests/Fixtures/WarmedInterface.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests\Fixtures;
|
||||
|
||||
interface WarmedInterface
|
||||
{
|
||||
}
|
||||
@@ -11,9 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\Psr4ClassLoader;
|
||||
|
||||
class Psr4ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class Psr4ClassLoaderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $className
|
||||
@@ -24,7 +28,7 @@ class Psr4ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader = new Psr4ClassLoader();
|
||||
$loader->addPrefix(
|
||||
'Acme\\DemoLib',
|
||||
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'psr-4'
|
||||
__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'psr-4'
|
||||
);
|
||||
$loader->loadClass($className);
|
||||
$this->assertTrue(class_exists($className), sprintf('loadClass() should load %s', $className));
|
||||
@@ -35,12 +39,12 @@ class Psr4ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function getLoadClassTests()
|
||||
{
|
||||
return array(
|
||||
array('Acme\\DemoLib\\Foo'),
|
||||
array('Acme\\DemoLib\\Class_With_Underscores'),
|
||||
array('Acme\\DemoLib\\Lets\\Go\\Deeper\\Foo'),
|
||||
array('Acme\\DemoLib\\Lets\\Go\\Deeper\\Class_With_Underscores'),
|
||||
);
|
||||
return [
|
||||
['Acme\\DemoLib\\Foo'],
|
||||
['Acme\\DemoLib\\Class_With_Underscores'],
|
||||
['Acme\\DemoLib\\Lets\\Go\\Deeper\\Foo'],
|
||||
['Acme\\DemoLib\\Lets\\Go\\Deeper\\Class_With_Underscores'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +56,7 @@ class Psr4ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader = new Psr4ClassLoader();
|
||||
$loader->addPrefix(
|
||||
'Acme\\DemoLib',
|
||||
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'psr-4'
|
||||
__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'psr-4'
|
||||
);
|
||||
$loader->loadClass($className);
|
||||
$this->assertFalse(class_exists($className), sprintf('loadClass() should not load %s', $className));
|
||||
@@ -63,9 +67,9 @@ class Psr4ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function getLoadNonexistentClassTests()
|
||||
{
|
||||
return array(
|
||||
array('Acme\\DemoLib\\I_Do_Not_Exist'),
|
||||
array('UnknownVendor\\SomeLib\\I_Do_Not_Exist'),
|
||||
);
|
||||
return [
|
||||
['Acme\\DemoLib\\I_Do_Not_Exist'],
|
||||
['UnknownVendor\\SomeLib\\I_Do_Not_Exist'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\WinCacheClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use `composer install --apcu-autoloader` instead.', \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* WinCacheClassLoader implements a wrapping autoloader cached in WinCache.
|
||||
*
|
||||
@@ -43,6 +45,8 @@ namespace Symfony\Component\ClassLoader;
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
* @author Artem Ryzhkov <artem@smart-core.org>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use `composer install --apcu-autoloader` instead.
|
||||
*/
|
||||
class WinCacheClassLoader
|
||||
{
|
||||
@@ -56,8 +60,6 @@ class WinCacheClassLoader
|
||||
protected $decorated;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $prefix The WinCache namespace prefix to use
|
||||
* @param object $decorated A class loader object that implements the findFile() method
|
||||
*
|
||||
@@ -66,7 +68,7 @@ class WinCacheClassLoader
|
||||
*/
|
||||
public function __construct($prefix, $decorated)
|
||||
{
|
||||
if (!extension_loaded('wincache')) {
|
||||
if (!\extension_loaded('wincache')) {
|
||||
throw new \RuntimeException('Unable to use WinCacheClassLoader as WinCache is not enabled.');
|
||||
}
|
||||
|
||||
@@ -85,7 +87,7 @@ class WinCacheClassLoader
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
spl_autoload_register([$this, 'loadClass'], true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +95,7 @@ class WinCacheClassLoader
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
spl_autoload_unregister([$this, 'loadClass']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,6 +112,8 @@ class WinCacheClassLoader
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,6 +139,6 @@ class WinCacheClassLoader
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return call_user_func_array(array($this->decorated, $method), $args);
|
||||
return \call_user_func_array([$this->decorated, $method], $args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\XcacheClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use `composer install --apcu-autoloader` instead.', \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* XcacheClassLoader implements a wrapping autoloader cached in XCache for PHP 5.3.
|
||||
*
|
||||
@@ -43,21 +45,15 @@ namespace Symfony\Component\ClassLoader;
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use `composer install --apcu-autoloader` instead.
|
||||
*/
|
||||
class XcacheClassLoader
|
||||
{
|
||||
private $prefix;
|
||||
|
||||
/**
|
||||
* A class loader object that implements the findFile() method.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $decorated;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $prefix The XCache namespace prefix to use
|
||||
* @param object $decorated A class loader object that implements the findFile() method
|
||||
*
|
||||
@@ -66,7 +62,7 @@ class XcacheClassLoader
|
||||
*/
|
||||
public function __construct($prefix, $decorated)
|
||||
{
|
||||
if (!extension_loaded('xcache')) {
|
||||
if (!\extension_loaded('xcache')) {
|
||||
throw new \RuntimeException('Unable to use XcacheClassLoader as XCache is not enabled.');
|
||||
}
|
||||
|
||||
@@ -85,7 +81,7 @@ class XcacheClassLoader
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
spl_autoload_register([$this, 'loadClass'], true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +89,7 @@ class XcacheClassLoader
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
spl_autoload_unregister([$this, 'loadClass']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,6 +106,8 @@ class XcacheClassLoader
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,6 +134,6 @@ class XcacheClassLoader
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return call_user_func_array(array($this->decorated, $method), $args);
|
||||
return \call_user_func_array([$this->decorated, $method], $args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"php": ">=5.5.9"
|
||||
"php": "^5.5.9|>=7.0.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/finder": "~2.8|~3.0",
|
||||
"symfony/finder": "~2.8|~3.0|~4.0",
|
||||
"symfony/polyfill-apcu": "~1.1"
|
||||
},
|
||||
"suggest": {
|
||||
@@ -31,10 +31,5 @@
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
>
|
||||
<php>
|
||||
<ini name="error_reporting" value="-1" />
|
||||
|
||||
Reference in New Issue
Block a user