mirror of
https://github.com/symfony/class-loader.git
synced 2026-03-24 17:22:11 +01:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78710673c0 | ||
|
|
9dac4c57cf | ||
|
|
59ab31e13c | ||
|
|
eb2590d94c | ||
|
|
5d77753a96 | ||
|
|
f4278d53d1 | ||
|
|
9ae87e8c34 | ||
|
|
f8843095b2 | ||
|
|
2c4235602f | ||
|
|
8bfdaa2e7a | ||
|
|
fdb4806d2e | ||
|
|
b6e2bb88a8 | ||
|
|
64d2af707a | ||
|
|
44816c55e9 | ||
|
|
1108382429 | ||
|
|
2e19afbcc7 | ||
|
|
65ac4dbf59 | ||
|
|
c060834942 | ||
|
|
886fe1940b |
@@ -57,8 +57,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
|
||||
*
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\ApcUniversalClassLoader class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Component\ClassLoader\ApcClassLoader class instead.', E_USER_DEPRECATED);
|
||||
@trigger_error('The '.__NAMESPACE__.'\ApcUniversalClassLoader class is deprecated since Symfony 2.7 and will be removed in 3.0. Use the Symfony\Component\ClassLoader\ApcClassLoader class instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* ApcUniversalClassLoader implements a "universal" autoloader cached in APC for PHP 5.3.
|
||||
@@ -68,8 +68,6 @@ class ApcUniversalClassLoader extends UniversalClassLoader
|
||||
private $prefix;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $prefix A prefix to create a namespace in APC
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
|
||||
@@ -62,8 +62,8 @@ class ClassCollectionLoader
|
||||
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));
|
||||
}
|
||||
$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;
|
||||
@@ -104,10 +104,17 @@ class ClassCollectionLoader
|
||||
}
|
||||
}
|
||||
|
||||
$c = '(?:\s*+(?:(?:#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
|
||||
$strictTypesRegex = str_replace('.', $c, "'^<\?php\s.declare.\(.strict_types.=.1.\).;'is");
|
||||
$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(DIRECTORY_SEPARATOR, $cacheDir);
|
||||
$cacheDir = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $cacheDir));
|
||||
$files = array();
|
||||
$content = '';
|
||||
foreach (self::getOrderedClasses($classes) as $class) {
|
||||
@@ -118,8 +125,8 @@ class ClassCollectionLoader
|
||||
$files[] = $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]) {
|
||||
@@ -127,11 +134,11 @@ 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 = str_repeat('../', count($cacheDir) - $i).implode('/', $file);
|
||||
$file = '__DIR__.'.var_export('/'.$file, true);
|
||||
}
|
||||
|
||||
$c = "\nnamespace {require $file;}";
|
||||
@@ -208,7 +215,7 @@ class ClassCollectionLoader
|
||||
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]) {
|
||||
@@ -225,7 +232,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();
|
||||
@@ -268,7 +275,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());
|
||||
|
||||
@@ -281,8 +294,6 @@ 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
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
if (!defined('SYMFONY_TRAIT')) {
|
||||
if (PHP_VERSION_ID >= 50400) {
|
||||
if (\PHP_VERSION_ID >= 50400) {
|
||||
define('SYMFONY_TRAIT', T_TRAIT);
|
||||
} else {
|
||||
define('SYMFONY_TRAIT', 0);
|
||||
@@ -64,15 +64,15 @@ class ClassMapGenerator
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\DebugClassLoader class is deprecated since version 2.4 and will be removed in 3.0. Use the Symfony\Component\Debug\DebugClassLoader class instead.', E_USER_DEPRECATED);
|
||||
@trigger_error('The '.__NAMESPACE__.'\DebugClassLoader class is deprecated since Symfony 2.4 and will be removed in 3.0. Use the Symfony\Component\Debug\DebugClassLoader class instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Autoloader checking if the class is really defined in the file found.
|
||||
@@ -31,8 +31,6 @@ class DebugClassLoader
|
||||
private $classFinder;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param object $classFinder
|
||||
*/
|
||||
public function __construct($classFinder)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\DebugUniversalClassLoader class is deprecated since version 2.4 and will be removed in 3.0. Use the Symfony\Component\Debug\DebugClassLoader class instead.', E_USER_DEPRECATED);
|
||||
@trigger_error('The '.__NAMESPACE__.'\DebugUniversalClassLoader class is deprecated since Symfony 2.4 and will be removed in 3.0. Use the Symfony\Component\Debug\DebugClassLoader class instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Checks that the class is actually declared in the included file.
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2004-2016 Fabien Potencier
|
||||
Copyright (c) 2004-2018 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
|
||||
|
||||
@@ -21,8 +21,6 @@ class MapClassLoader
|
||||
private $map = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $map A map where keys are classes and values the absolute file path
|
||||
*/
|
||||
public function __construct(array $map)
|
||||
|
||||
@@ -20,9 +20,6 @@ namespace Symfony\Component\ClassLoader;
|
||||
*/
|
||||
class Psr4ClassLoader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $prefixes = array();
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
|
||||
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
|
||||
class ApcClassLoaderTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\ClassCollectionLoader;
|
||||
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/GInterface.php';
|
||||
@@ -18,7 +19,7 @@ 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
|
||||
class ClassCollectionLoaderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 5.4
|
||||
@@ -235,7 +236,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$strictTypes = defined('HHVM_VERSION') ? '' : "\nnamespace {require __DIR__.'/Fixtures/Namespaced/WithStrictTypes.php';}";
|
||||
|
||||
ClassCollectionLoader::load(
|
||||
array('Namespaced\\WithComments', 'Pearlike_WithComments', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
|
||||
array('Namespaced\\WithComments', 'Pearlike_WithComments', 'Namespaced\\WithDirMagic', 'Namespaced\\WithFileMagic', 'Namespaced\\WithHaltCompiler', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
|
||||
__DIR__,
|
||||
'bar',
|
||||
false
|
||||
@@ -275,6 +276,9 @@ 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))
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\ClassLoader;
|
||||
|
||||
class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
class ClassLoaderTest extends TestCase
|
||||
{
|
||||
public function testGetPrefixes()
|
||||
{
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
||||
|
||||
class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
class ClassMapGeneratorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var string|null
|
||||
@@ -76,9 +77,11 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
'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',
|
||||
),
|
||||
),
|
||||
'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',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array(
|
||||
'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',
|
||||
@@ -105,7 +108,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
)),
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID >= 50400) {
|
||||
if (\PHP_VERSION_ID >= 50400) {
|
||||
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
|
||||
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
@@ -116,7 +119,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
));
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID >= 50500) {
|
||||
if (\PHP_VERSION_ID >= 50500) {
|
||||
$data[] = array(__DIR__.'/Fixtures/php5.5', array(
|
||||
'ClassCons\\Foo' => __DIR__.'/Fixtures/php5.5/class_cons.php',
|
||||
));
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class LegacyApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
class LegacyApcUniversalClassLoaderTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
@@ -42,17 +43,17 @@ class LegacyApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($loader->findFile('\LegacyApc\Namespaced\FooBar'), apcu_fetch('test.prefix.\LegacyApc\Namespaced\FooBar'), '__construct() takes a prefix as its first argument');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassTests
|
||||
*/
|
||||
public function testLoadClass($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.');
|
||||
$loader->registerNamespace('LegacyApc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('LegacyApc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
/**
|
||||
* @dataProvider getLoadClassTests
|
||||
*/
|
||||
public function testLoadClass($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.');
|
||||
$loader->registerNamespace('LegacyApc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('LegacyApc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassTests()
|
||||
{
|
||||
@@ -62,19 +63,19 @@ class LegacyApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassFromFallbackTests
|
||||
*/
|
||||
public function testLoadClassFromFallback($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.fallback');
|
||||
$loader->registerNamespace('LegacyApc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('LegacyApc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerNamespaceFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/LegacyApc/fallback'));
|
||||
$loader->registerPrefixFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/LegacyApc/fallback'));
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
/**
|
||||
* @dataProvider getLoadClassFromFallbackTests
|
||||
*/
|
||||
public function testLoadClassFromFallback($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.fallback');
|
||||
$loader->registerNamespace('LegacyApc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('LegacyApc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerNamespaceFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/LegacyApc/fallback'));
|
||||
$loader->registerPrefixFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/LegacyApc/fallback'));
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassFromFallbackTests()
|
||||
{
|
||||
@@ -86,18 +87,18 @@ class LegacyApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassNamespaceCollisionTests
|
||||
*/
|
||||
public function testLoadClassNamespaceCollision($namespaces, $className, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.collision.');
|
||||
$loader->registerNamespaces($namespaces);
|
||||
/**
|
||||
* @dataProvider getLoadClassNamespaceCollisionTests
|
||||
*/
|
||||
public function testLoadClassNamespaceCollision($namespaces, $className, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.collision.');
|
||||
$loader->registerNamespaces($namespaces);
|
||||
|
||||
$loader->loadClass($className);
|
||||
$loader->loadClass($className);
|
||||
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassNamespaceCollisionTests()
|
||||
{
|
||||
@@ -137,17 +138,17 @@ class LegacyApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassPrefixCollisionTests
|
||||
*/
|
||||
public function testLoadClassPrefixCollision($prefixes, $className, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.collision.');
|
||||
$loader->registerPrefixes($prefixes);
|
||||
/**
|
||||
* @dataProvider getLoadClassPrefixCollisionTests
|
||||
*/
|
||||
public function testLoadClassPrefixCollision($prefixes, $className, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.collision.');
|
||||
$loader->registerPrefixes($prefixes);
|
||||
|
||||
$loader->loadClass($className);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
$loader->loadClass($className);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassPrefixCollisionTests()
|
||||
{
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\UniversalClassLoader;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class LegacyUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
class LegacyUniversalClassLoaderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getLoadClassTests
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\ClassLoader\Psr4ClassLoader;
|
||||
|
||||
class Psr4ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
class Psr4ClassLoaderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $className
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\UniversalClassLoader class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Component\ClassLoader\ClassLoader class instead.', E_USER_DEPRECATED);
|
||||
@trigger_error('The '.__NAMESPACE__.'\UniversalClassLoader class is deprecated since Symfony 2.7 and will be removed in 3.0. Use the Symfony\Component\ClassLoader\ClassLoader class instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* UniversalClassLoader implements a "universal" autoloader for PHP 5.3.
|
||||
|
||||
@@ -58,8 +58,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
|
||||
*
|
||||
|
||||
@@ -49,17 +49,9 @@ namespace Symfony\Component\ClassLoader;
|
||||
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
|
||||
*
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"symfony/polyfill-apcu": "~1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/finder": "~2.0,>=2.0.5|~3.0.0"
|
||||
"symfony/finder": "^2.0.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Component\\ClassLoader\\": "" },
|
||||
@@ -31,7 +31,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.8-dev"
|
||||
"dev-master": "2.7-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
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