Compare commits

...

45 Commits
2.4 ... v2.3.37

Author SHA1 Message Date
Diego Saint Esteben
6abee87b00 Update copyright year 2016-01-01 23:53:47 -03:00
Fabien Potencier
f43622ab16 minor #17085 [2.3] Static Code Analysis for Components (kalessil)
This PR was squashed before being merged into the 2.3 branch (closes #17085).

Discussion
----------

[2.3] Static Code Analysis for Components

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Static Code Analysis with Php Inspections (EA Extended):
    - remaining mkdir race conditions
    - continue miss-usage in switch

Commits
-------

6d303c7 [2.3] Static Code Analysis for Components
2015-12-31 19:24:03 +01:00
Vladimir Reznichenko
7b12dc6915 [2.3] Static Code Analysis for Components 2015-12-31 19:24:01 +01:00
Gregor Harlan
f604d121fa use nowdoc instead of heredoc 2015-12-21 17:05:00 +01:00
Dariusz Ruminski
c77176c94f CS: general fixes 2015-12-01 23:08:33 +01:00
Nicolas Grekas
25d492fa74 [ClassLoader] Fix parsing namespace when token_get_all() is missing 2015-11-25 18:16:22 +01:00
Nicolas Grekas
bd1ffcea9c Add missing exclusions from phpunit.xml.dist 2015-11-18 09:19:46 +01:00
Anne-Sophie Bachelard
f0a379b040 added the new Composer exclude-from-classmap option 2015-10-30 12:48:51 -07:00
Nicolas Grekas
a4e0538494 [Process] Inherit env vars by default in PhpProcess 2015-10-20 18:32:03 +02:00
Nicolas Grekas
2ae3b6f88a [ci] Fix tests requirements 2015-10-12 11:06:32 +02:00
Nicolas Grekas
480abf8101 [ci] SymfonyTestsListener is now auto-registered 2015-10-11 11:37:49 +02:00
Nicolas Grekas
7c31a493f4 minor #16190 [ci] Enable collecting and replaying skipped tests (nicolas-grekas)
This PR was merged into the 2.3 branch.

Discussion
----------

[ci] Enable collecting and replaying skipped tests

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16184
| License       | MIT
| Doc PR        | -

Commits
-------

4032c88 [ci] Enable collecting and replaying skipped tests
2015-10-10 11:14:14 +02:00
Nicolas Grekas
89922ecb2b [tests] Use @requires annotation when possible 2015-10-10 10:57:40 +02:00
Nicolas Grekas
00efe62b37 [ci] Enable collecting and replaying skipped tests 2015-10-10 10:46:02 +02:00
Fabien Potencier
4a439e796e fixed CS 2015-10-06 17:46:46 +02:00
Remi Collet
519ac47b5f avoid duplicated path with addPrefix 2015-10-06 17:11:44 +02:00
Tobias Schultze
e0d78d3cfd remove api tags from code 2015-09-28 19:11:22 +02:00
Tobias Schultze
931f370587 consistently use str_replace to unify directory separators 2015-08-25 14:59:33 +02:00
WouterJ
b9ce73294e Skip ::class constant 2015-07-27 20:12:35 +02:00
Vladimir Reznichenko
82f4e6502e [2.3] Static Code Analysis for Components 2015-06-21 22:11:32 +02:00
Fabien Potencier
598dfd4610 minor #14121 CS: Pre incrementation/decrementation should be used if possible (gharlan)
This PR was merged into the 2.3 branch.

Discussion
----------

CS: Pre incrementation/decrementation should be used if possible

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Fixes provided by new fixer: https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/1113

If this pr is merged I would change the level of the fixer to `symfony`.

Commits
-------

c5123d6 CS: Pre incrementation/decrementation should be used if possible
2015-05-15 15:28:34 +02:00
Christian Flothmann
85b2532f2f link to https://symfony.com where possible 2015-05-01 16:06:45 +02:00
Gregor Harlan
1ecb64f0c2 CS: Pre incrementation/decrementation should be used if possible 2015-04-07 19:54:22 +02:00
Dariusz Ruminski
cc6272033e CS: fixes 2015-03-27 10:02:23 +01:00
Nicolas Grekas
41f582851c [2.3] require-dev PHPUnit bridge 2015-02-24 11:24:26 +01:00
Fabien Potencier
e722b63c50 renamed composer.phar to composer to be consistent with the Symfony docs 2015-02-08 08:41:14 +01:00
Fabien Potencier
ad6b79e597 minor #13206 [2.3] Cleanup deprecations (nicolas-grekas)
This PR was merged into the 2.3 branch.

Discussion
----------

[2.3] Cleanup deprecations

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | let's see
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

d649bef [2.3] Remove useless tests skips
1d68ad3 [2.3] Cleanup deprecations
2015-01-03 15:49:25 +01:00
Nicolas Grekas
b44bb69fd2 [2.3] Remove useless tests skips 2015-01-03 14:14:51 +01:00
Hugo Hamon
731d5a42fa [ClassLoader] removes deprecated classes from documentation. 2015-01-03 14:04:11 +01:00
Saro0h
34e525229a Updated copyright to 2015 2015-01-01 13:56:52 +01:00
Graham Campbell
d7819f2f17 [2.3] CS And DocBlock Fixes 2014-12-22 16:58:09 +01:00
Graham Campbell
2f8a6f96e2 [2.3] CS Fixes 2014-12-21 15:56:12 +01:00
sarah khalil
53074e1533 [Tests] Silenced all deprecations in tests for 2.3 2014-12-18 20:00:19 +01:00
Nicolas Grekas
35e977baae Test components using their lowest possible deps 2014-12-15 11:45:17 +01:00
Szijarto Tamas
e2a07cb502 [ClassLoader] Fix undefined index in ClassCollectionLoader 2014-12-04 22:06:34 +01:00
Graham Campbell
307598c291 Docblock fixes 2014-11-30 13:33:44 +00:00
Fabien Potencier
8defca3a59 bug #12716 [ClassLoader] define constant only if it wasn't defined before (xabbuh)
This PR was merged into the 2.3 branch.

Discussion
----------

[ClassLoader] define constant only if it wasn't defined before

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

388229b define constant only if it wasn't defined before
2014-11-29 13:55:31 +01:00
Christian Flothmann
47b66544f8 define constant only if it wasn't defined before 2014-11-29 13:36:20 +01:00
Pascal Borreli
a57eb271c2 Fixed typos 2014-11-29 11:42:24 +01:00
Christian Flothmann
4993c270bb compare version using PHP_VERSION_ID
To let opcode caches optimize cached code, the `PHP_VERSION_ID`
constant is used to detect the current PHP version instead of calling
`version_compare()` with `PHP_VERSION`.
2014-11-17 17:27:42 +01:00
Fabien Potencier
0d2d67d18f minor #12372 [Yaml] don't override internal PHP constants (xabbuh)
This PR was merged into the 2.3 branch.

Discussion
----------

[Yaml] don't override internal PHP constants

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #11783
| License       | MIT
| Doc PR        |

Commits
-------

376cc03 don't override internal PHP constants
2014-11-16 19:04:21 +01:00
Christian Flothmann
ea9e58e776 don't override internal PHP constants 2014-11-16 18:59:41 +01:00
Geert De Deckere
09a40f5433 [ClassLoader] Cast $useIncludePath property to boolean 2014-11-02 01:04:15 +01:00
Disquedur
46754025d0 Remove aligned '=>' and '=' 2014-10-26 08:30:58 +01:00
Laurent Ghirardotti
6b87e5db15 [Doc] Use Markdown syntax highlighting 2014-10-01 07:38:33 +02:00
24 changed files with 313 additions and 195 deletions

View File

@@ -17,11 +17,19 @@ namespace Symfony\Component\ClassLoader;
* It expects an object implementing a findFile method to find the file. This
* allows using it as a wrapper around the other loaders of the component (the
* ClassLoader and the UniversalClassLoader for instance) but also around any
* other autoloader following this convention (the Composer one for instance)
* other autoloaders following this convention (the Composer one for instance).
*
* // with a Symfony autoloader
* use Symfony\Component\ClassLoader\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->addPrefix('Symfony\Component', __DIR__.'/component');
* $loader->addPrefix('Symfony', __DIR__.'/framework');
*
* // register classes with namespaces
* // or with a Composer autoloader
* use Composer\Autoload\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
@@ -36,31 +44,26 @@ namespace Symfony\Component\ClassLoader;
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Kris Wallsmith <kris@symfony.com>
*
* @api
*/
class ApcClassLoader
{
private $prefix;
/**
* The class loader object being decorated.
* A class loader object that implements the findFile() method.
*
* @var object
* A class loader object that implements the findFile() method.
*/
protected $decorated;
/**
* Constructor.
*
* @param string $prefix The APC namespace prefix to use.
* @param object $decorated A class loader object that implements the findFile() method.
* @param string $prefix The APC namespace prefix to use.
* @param object $decorated A class loader object that implements the findFile() method.
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*
* @api
*/
public function __construct($prefix, $decorated)
{
@@ -79,7 +82,7 @@ class ApcClassLoader
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -99,7 +102,7 @@ class ApcClassLoader
*
* @param string $class The name of the class
*
* @return bool|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{

View File

@@ -37,8 +37,8 @@ namespace Symfony\Component\ClassLoader;
* // register classes with namespaces
* $loader->registerNamespaces(array(
* 'Symfony\Component' => __DIR__.'/component',
* 'Symfony' => __DIR__.'/framework',
* 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
* 'Symfony' => __DIR__.'/framework',
* 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
* ));
*
* // register a library using the PEAR naming convention
@@ -57,8 +57,6 @@ namespace Symfony\Component\ClassLoader;
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Kris Wallsmith <kris@symfony.com>
*
* @api
*/
class ApcUniversalClassLoader extends UniversalClassLoader
{
@@ -70,8 +68,6 @@ class ApcUniversalClassLoader extends UniversalClassLoader
* @param string $prefix A prefix to create a namespace in APC
*
* @throws \RuntimeException
*
* @api
*/
public function __construct($prefix)
{

View File

@@ -25,12 +25,12 @@ class ClassCollectionLoader
/**
* Loads a list of classes and caches them in one big file.
*
* @param array $classes An array of classes to load
* @param string $cacheDir A cache directory
* @param string $name The cache name prefix
* @param bool $autoReload Whether to flush the cache when the cache is stale or not
* @param bool $adaptive Whether to remove already declared classes or not
* @param string $extension File extension of the resulting file
* @param array $classes An array of classes to load
* @param string $cacheDir A cache directory
* @param string $name The cache name prefix
* @param bool $autoReload Whether to flush the cache when the cache is stale or not
* @param bool $adaptive Whether to remove already declared classes or not
* @param string $extension File extension of the resulting file
*
* @throws \InvalidArgumentException When class can't be loaded
*/
@@ -116,8 +116,8 @@ class ClassCollectionLoader
}
// cache the core classes
if (!is_dir(dirname($cache))) {
mkdir(dirname($cache), 0777, true);
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
}
self::writeCacheFile($cache, '<?php '.$content);
@@ -137,8 +137,8 @@ class ClassCollectionLoader
public static function fixNamespaceDeclarations($source)
{
if (!function_exists('token_get_all') || !self::$useTokenizer) {
if (preg_match('/namespace(.*?)\s*;/', $source)) {
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
if (preg_match('/(^|\s)namespace(.*?)\s*;/', $source)) {
$source = preg_replace('/(^|\s)namespace(.*?)\s*;/', "$1namespace$2\n{", $source)."}\n";
}
return $source;
@@ -283,7 +283,7 @@ class ClassCollectionLoader
$traits = array();
if (function_exists('get_declared_traits')) {
if (method_exists('ReflectionClass', 'getTraits')) {
foreach ($classes as $c) {
foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
if ($trait !== $c) {
@@ -335,10 +335,10 @@ class ClassCollectionLoader
* This function does not check for circular dependencies as it should never
* occur with PHP traits.
*
* @param array $tree The dependency tree
* @param \ReflectionClass $node The node
* @param \ArrayObject $resolved An array of already resolved dependencies
* @param \ArrayObject $unresolved An array of dependencies to be resolved
* @param array $tree The dependency tree
* @param \ReflectionClass $node The node
* @param \ArrayObject $resolved An array of already resolved dependencies
* @param \ArrayObject $unresolved An array of dependencies to be resolved
*
* @return \ArrayObject The dependencies for the given node
*
@@ -353,14 +353,17 @@ class ClassCollectionLoader
$unresolved = new \ArrayObject();
}
$nodeName = $node->getName();
$unresolved[$nodeName] = $node;
foreach ($tree[$nodeName] as $dependency) {
if (!$resolved->offsetExists($dependency->getName())) {
self::resolveDependencies($tree, $dependency, $resolved, $unresolved);
if (isset($tree[$nodeName])) {
$unresolved[$nodeName] = $node;
foreach ($tree[$nodeName] as $dependency) {
if (!$resolved->offsetExists($dependency->getName())) {
self::resolveDependencies($tree, $dependency, $resolved, $unresolved);
}
}
$resolved[$nodeName] = $node;
unset($unresolved[$nodeName]);
}
$resolved[$nodeName] = $node;
unset($unresolved[$nodeName]);
return $resolved;
}

View File

@@ -12,7 +12,7 @@
namespace Symfony\Component\ClassLoader;
/**
* ClassLoader implements an PSR-0 class loader
* ClassLoader implements an PSR-0 class loader.
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
*
@@ -76,7 +76,7 @@ class ClassLoader
}
/**
* Registers a set of classes
* Registers a set of classes.
*
* @param string $prefix The classes prefix
* @param array|string $paths The location(s) of the classes
@@ -91,23 +91,27 @@ class ClassLoader
return;
}
if (isset($this->prefixes[$prefix])) {
$this->prefixes[$prefix] = array_merge(
$this->prefixes[$prefix],
(array) $paths
);
if (is_array($paths)) {
$this->prefixes[$prefix] = array_unique(array_merge(
$this->prefixes[$prefix],
$paths
));
} elseif (!in_array($paths, $this->prefixes[$prefix])) {
$this->prefixes[$prefix][] = $paths;
}
} else {
$this->prefixes[$prefix] = (array) $paths;
$this->prefixes[$prefix] = array_unique((array) $paths);
}
}
/**
* Turns on searching the include for class files.
*
* @param bool $useIncludePath
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
$this->useIncludePath = (bool) $useIncludePath;
}
/**
@@ -124,7 +128,7 @@ class ClassLoader
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -144,7 +148,7 @@ class ClassLoader
*
* @param string $class The name of the class
*
* @return bool|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{

View File

@@ -11,19 +11,23 @@
namespace Symfony\Component\ClassLoader;
if (!defined('T_TRAIT')) {
define('T_TRAIT', 0);
if (!defined('SYMFONY_TRAIT')) {
if (PHP_VERSION_ID >= 50400) {
define('SYMFONY_TRAIT', T_TRAIT);
} else {
define('SYMFONY_TRAIT', 0);
}
}
/**
* ClassMapGenerator
* ClassMapGenerator.
*
* @author Gyula Sallai <salla016@gmail.com>
*/
class ClassMapGenerator
{
/**
* Generate a class map file
* Generate a class map file.
*
* @param array|string $dirs Directories or a single path to search in
* @param string $file The name of the class map file
@@ -41,7 +45,7 @@ class ClassMapGenerator
}
/**
* Iterate over all files in the given directory searching for classes
* Iterate over all files in the given directory searching for classes.
*
* @param \Iterator|string $dir The directory to search in or an iterator
*
@@ -77,7 +81,7 @@ class ClassMapGenerator
}
/**
* Extract the classes in the given file
* Extract the classes in the given file.
*
* @param string $path The file to check
*
@@ -86,12 +90,12 @@ class ClassMapGenerator
private static function findClasses($path)
{
$contents = file_get_contents($path);
$tokens = token_get_all($contents);
$tokens = token_get_all($contents);
$classes = array();
$namespace = '';
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
for ($i = 0, $max = count($tokens); $i < $max; ++$i) {
$token = $tokens[$i];
if (is_string($token)) {
@@ -113,7 +117,26 @@ class ClassMapGenerator
break;
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:
case SYMFONY_TRAIT:
// Skip usage of ::class constant
$isClassConstant = false;
for ($j = $i - 1; $j > 0; --$j) {
if (is_string($tokens[$j])) {
break;
}
if (T_DOUBLE_COLON === $tokens[$j][0]) {
$isClassConstant = true;
break;
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
break;
}
}
if ($isClassConstant) {
break;
}
// Find the classname
while (($t = $tokens[++$i]) && is_array($t)) {
if (T_STRING === $t[0]) {

View File

@@ -20,8 +20,6 @@ namespace Symfony\Component\ClassLoader;
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Christophe Coevoet <stof@notk.org>
*
* @api
*/
class DebugClassLoader
{
@@ -31,8 +29,6 @@ class DebugClassLoader
* Constructor.
*
* @param object $classFinder
*
* @api
*/
public function __construct($classFinder)
{
@@ -70,7 +66,7 @@ class DebugClassLoader
}
/**
* Finds a file by class name
* Finds a file by class name.
*
* @param string $class A class name to resolve to file
*
@@ -86,7 +82,7 @@ class DebugClassLoader
*
* @param string $class The name of the class
*
* @return bool|null True, if loaded
* @return bool|null True, if loaded
*
* @throws \RuntimeException
*/

View File

@@ -1,4 +1,4 @@
Copyright (c) 2004-2014 Fabien Potencier
Copyright (c) 2004-2016 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -33,7 +33,7 @@ class MapClassLoader
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{

View File

@@ -4,56 +4,72 @@ ClassLoader Component
ClassLoader loads your project classes automatically if they follow some
standard PHP conventions.
The Universal ClassLoader is able to autoload classes that implement the PSR-0
The ClassLoader object is able to autoload classes that implement the PSR-0
standard or the PEAR naming convention.
First, register the autoloader:
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
```php
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Symfony\Component\ClassLoader\ClassLoader;
$loader = new UniversalClassLoader();
$loader->register();
$loader = new ClassLoader();
$loader->register();
```
Then, register some namespaces with the `registerNamespace()` method:
Then, register some namespaces with the `addPrefix()` method:
$loader->registerNamespace('Symfony', __DIR__.'/src');
$loader->registerNamespace('Monolog', __DIR__.'/vendor/monolog/src');
```php
$loader->addPrefix('Symfony', __DIR__.'/src');
$loader->addPrefix('Monolog', __DIR__.'/vendor/monolog/src');
```
The `registerNamespace()` method takes a namespace prefix and a path where to
The `addPrefix()` method takes a namespace prefix and a path where to
look for the classes as arguments.
You can also register a sub-namespaces:
$loader->registerNamespace('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');
```php
$loader->addPrefix('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');
```
The order of registration is significant and the first registered namespace
takes precedence over later registered one.
You can also register more than one path for a given namespace:
$loader->registerNamespace('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
```php
$loader->addPrefix('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
```
Alternatively, you can use the `registerNamespaces()` method to register more
Alternatively, you can use the `addPrefixes()` method to register more
than one namespace at once:
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
'Monolog' => __DIR__.'/vendor/monolog/src',
));
```php
$loader->addPrefixes(array(
'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
'Monolog' => __DIR__.'/vendor/monolog/src',
));
```
For better performance, you can use the APC based version of the universal
class loader:
For better performance, you can use the APC class loader:
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
```php
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcClassLoader.php';
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
use Symfony\Component\ClassLoader\ClassLoader;
use Symfony\Component\ClassLoader\ApcClassLoader;
$loader = new ApcUniversalClassLoader('apc.prefix.');
$loader = new ClassLoader();
$loader->addPrefix('Symfony', __DIR__.'/src');
$loader = new ApcClassLoader('apc.prefix.', $loader);
$loader->register();
```
Furthermore, the component provides tools to aggregate classes into a single
file, which is especially useful to improve performance on servers that do not
@@ -65,5 +81,5 @@ Resources
You can run the unit tests with the following command:
$ cd path/to/Symfony/Component/ClassLoader/
$ composer.phar install
$ composer install
$ phpunit

View File

@@ -13,18 +13,17 @@ namespace Symfony\Component\ClassLoader\Tests;
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
/**
* @requires extension apc
*/
class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!extension_loaded('apc')) {
$this->markTestSkipped('The apc extension is not available.');
}
if (!(ini_get('apc.enabled') && ini_get('apc.enable_cli'))) {
$this->markTestSkipped('The apc extension is available, but not enabled.');
} else {
if (ini_get('apc.enabled') && ini_get('apc.enable_cli')) {
apc_clear_cache('user');
} else {
$this->markTestSkipped('APC is not enabled.');
}
}

View File

@@ -20,14 +20,11 @@ require_once __DIR__.'/Fixtures/ClassesWithParents/A.php';
class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
{
/**
* @requires PHP 5.4
*/
public function testTraitDependencies()
{
if (version_compare(phpversion(), '5.4', '<')) {
$this->markTestSkipped('Requires PHP > 5.4');
return;
}
require_once __DIR__.'/Fixtures/deps/traits.php';
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
@@ -97,15 +94,10 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider getDifferentOrdersForTraits
* @requires PHP 5.4
*/
public function testClassWithTraitsReordering(array $classes)
{
if (version_compare(phpversion(), '5.4', '<')) {
$this->markTestSkipped('Requires PHP > 5.4');
return;
}
require_once __DIR__.'/Fixtures/ClassesWithParents/ATrait.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/BTrait.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/CTrait.php';
@@ -146,6 +138,35 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
);
}
/**
* @requires PHP 5.4
*/
public function testFixClassWithTraitsOrdering()
{
require_once __DIR__.'/Fixtures/ClassesWithParents/CTrait.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/F.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/G.php';
$classes = array(
'ClassesWithParents\\F',
'ClassesWithParents\\G',
);
$expected = array(
'ClassesWithParents\\CTrait',
'ClassesWithParents\\F',
'ClassesWithParents\\G',
);
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
$m = $r->getMethod('getOrderedClasses');
$m->setAccessible(true);
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
}
/**
* @dataProvider getFixNamespaceDeclarationsData
*/
@@ -184,7 +205,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
array("namespace Bar ;\nclass Foo {}\n", "namespace Bar\n{\nclass Foo {}\n}\n"),
array("namespace Foo\Bar;\nclass Foo {}\n", "namespace Foo\Bar\n{\nclass Foo {}\n}\n"),
array("namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n", "namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n"),
array("namespace\n{\nclass Foo {}\n}\n", "namespace\n{\nclass Foo {}\n}\n"),
array("\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n", "\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n"),
);
}
@@ -220,26 +241,26 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
spl_autoload_unregister($r);
$this->assertEquals(<<<EOF
$this->assertEquals(<<<'EOF'
namespace Namespaced
{
class WithComments
{
public static \$loaded = true;
public static $loaded = true;
}
\$string ='string shoult not be modified {\$string}';
\$heredoc = (<<<HD
$string ='string should not be modified {$string}';
$heredoc = (<<<HD
Heredoc should not be modified {\$string}
Heredoc should not be modified {$string}
HD
);
\$nowdoc =<<<'ND'
$nowdoc =<<<'ND'
Nowdoc should not be modified {\$string}
Nowdoc should not be modified {$string}
ND
@@ -249,7 +270,7 @@ namespace
{
class Pearlike_WithComments
{
public static \$loaded = true;
public static $loaded = true;
}
}
EOF

View File

@@ -76,14 +76,36 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
);
}
public function testAddPrefix()
public function testAddPrefixSingle()
{
$loader = new ClassLoader();
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
$prefixes = $loader->getPrefixes();
$this->assertArrayHasKey('Foo', $prefixes);
$this->assertCount(1, $prefixes['Foo']);
}
public function testAddPrefixesSingle()
{
$loader = new ClassLoader();
$loader->addPrefixes(array('Foo' => array('foo', 'foo')));
$loader->addPrefixes(array('Foo' => array('foo')));
$prefixes = $loader->getPrefixes();
$this->assertArrayHasKey('Foo', $prefixes);
$this->assertCount(1, $prefixes['Foo'], print_r($prefixes, true));
}
public function testAddPrefixMulti()
{
$loader = new ClassLoader();
$loader->addPrefix('Foo', 'foo');
$loader->addPrefix('Foo', 'bar');
$prefixes = $loader->getPrefixes();
$this->assertArrayHasKey('Foo', $prefixes);
$this->assertCount(2, $prefixes['Foo']);
$this->assertContains('foo', $prefixes['Foo']);
$this->assertContains('bar', $prefixes['Foo']);
}
public function testUseIncludePath()

View File

@@ -16,13 +16,13 @@ use Symfony\Component\ClassLoader\ClassMapGenerator;
class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var string $workspace
* @var string|null
*/
private $workspace = null;
public function prepare_workspace()
{
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().rand(0, 1000);
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().mt_rand(0, 1000);
mkdir($this->workspace, 0777, true);
$this->workspace = realpath($this->workspace);
}
@@ -47,7 +47,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider getTestCreateMapTests
*/
public function testDump($directory, $expected)
public function testDump($directory)
{
$this->prepare_workspace();
@@ -72,9 +72,9 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
{
$data = array(
array(__DIR__.'/Fixtures/Namespaced', array(
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.php',
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.php',
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
'Namespaced\\WithComments' => realpath(__DIR__).'/Fixtures/Namespaced/WithComments.php',
),
),
@@ -85,26 +85,26 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
'NamespaceCollision\\C\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Foo.php',
)),
array(__DIR__.'/Fixtures/Pearlike', array(
'Pearlike_Foo' => realpath(__DIR__).'/Fixtures/Pearlike/Foo.php',
'Pearlike_Bar' => realpath(__DIR__).'/Fixtures/Pearlike/Bar.php',
'Pearlike_Baz' => realpath(__DIR__).'/Fixtures/Pearlike/Baz.php',
'Pearlike_Foo' => realpath(__DIR__).'/Fixtures/Pearlike/Foo.php',
'Pearlike_Bar' => realpath(__DIR__).'/Fixtures/Pearlike/Bar.php',
'Pearlike_Baz' => realpath(__DIR__).'/Fixtures/Pearlike/Baz.php',
'Pearlike_WithComments' => realpath(__DIR__).'/Fixtures/Pearlike/WithComments.php',
)),
array(__DIR__.'/Fixtures/classmap', array(
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Beta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Beta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php',
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
)),
);
if (version_compare(PHP_VERSION, '5.4', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
@@ -115,15 +115,17 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
));
}
if (PHP_VERSION_ID >= 50500) {
$data[] = array(__DIR__.'/Fixtures/php5.5', array(
'ClassCons\\Foo' => __DIR__.'/Fixtures/php5.5/class_cons.php',
));
}
return $data;
}
public function testCreateMapFinderSupport()
{
if (!class_exists('Symfony\\Component\\Finder\\Finder')) {
$this->markTestSkipped('Finder component is not available');
}
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()->in(__DIR__.'/Fixtures/beta/NamespaceCollision');
@@ -138,10 +140,10 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
protected function assertEqualsNormalized($expected, $actual, $message = null)
{
foreach ($expected as $ns => $path) {
$expected[$ns] = strtr($path, '\\', '/');
$expected[$ns] = str_replace('\\', '/', $path);
}
foreach ($actual as $ns => $path) {
$actual[$ns] = strtr($path, '\\', '/');
$actual[$ns] = str_replace('\\', '/', $path);
}
$this->assertEquals($expected, $actual, $message);
}

View File

@@ -0,0 +1,8 @@
<?php
namespace ClassesWithParents;
class F
{
use CTrait;
}

View File

@@ -0,0 +1,8 @@
<?php
namespace ClassesWithParents;
class G
{
use CTrait;
}

View File

@@ -17,7 +17,7 @@ class WithComments
public static $loaded = true;
}
$string = 'string shoult not be modified {$string}';
$string = 'string should not be modified {$string}';
$heredoc = (<<<HD

View File

@@ -1,4 +1,5 @@
<?php
namespace {
class A
{

View File

@@ -1,4 +1,5 @@
<?php
namespace {
trait TFoo
{

View File

@@ -0,0 +1,11 @@
<?php
namespace ClassCons;
class Foo
{
public function __construct()
{
\Foo\TBar/* foo */::class;
}
}

View File

@@ -32,8 +32,8 @@ namespace Symfony\Component\ClassLoader;
* // register classes with namespaces
* $loader->registerNamespaces(array(
* 'Symfony\Component' => __DIR__.'/component',
* 'Symfony' => __DIR__.'/framework',
* 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
* 'Symfony' => __DIR__.'/framework',
* 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
* ));
*
* // register a library using the PEAR naming convention
@@ -55,8 +55,6 @@ namespace Symfony\Component\ClassLoader;
* found before giving up.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/
class UniversalClassLoader
{
@@ -68,13 +66,13 @@ class UniversalClassLoader
/**
* Turns on searching the include for class files. Allows easy loading
* of installed PEAR packages
* of installed PEAR packages.
*
* @param bool $useIncludePath
* @param bool $useIncludePath
*/
public function useIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
$this->useIncludePath = (bool) $useIncludePath;
}
/**
@@ -132,8 +130,6 @@ class UniversalClassLoader
* Registers the directory to use as a fallback for namespaces.
*
* @param array $dirs An array of directories
*
* @api
*/
public function registerNamespaceFallbacks(array $dirs)
{
@@ -154,8 +150,6 @@ class UniversalClassLoader
* Registers directories to use as a fallback for class prefixes.
*
* @param array $dirs An array of directories
*
* @api
*/
public function registerPrefixFallbacks(array $dirs)
{
@@ -173,11 +167,9 @@ class UniversalClassLoader
}
/**
* Registers an array of namespaces
* Registers an array of namespaces.
*
* @param array $namespaces An array of namespaces (namespaces as keys and locations as values)
*
* @api
*/
public function registerNamespaces(array $namespaces)
{
@@ -191,8 +183,6 @@ class UniversalClassLoader
*
* @param string $namespace The namespace
* @param array|string $paths The location(s) of the namespace
*
* @api
*/
public function registerNamespace($namespace, $paths)
{
@@ -203,8 +193,6 @@ class UniversalClassLoader
* Registers an array of classes using the PEAR naming convention.
*
* @param array $classes An array of classes (prefixes as keys and locations as values)
*
* @api
*/
public function registerPrefixes(array $classes)
{
@@ -218,8 +206,6 @@ class UniversalClassLoader
*
* @param string $prefix The classes prefix
* @param array|string $paths The location(s) of the classes
*
* @api
*/
public function registerPrefix($prefix, $paths)
{
@@ -229,9 +215,7 @@ class UniversalClassLoader
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*
* @api
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -243,7 +227,7 @@ class UniversalClassLoader
*
* @param string $class The name of the class
*
* @return bool|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{

View File

@@ -17,11 +17,19 @@ namespace Symfony\Component\ClassLoader;
* It expects an object implementing a findFile method to find the file. This
* allow using it as a wrapper around the other loaders of the component (the
* ClassLoader and the UniversalClassLoader for instance) but also around any
* other autoloader following this convention (the Composer one for instance)
* other autoloaders following this convention (the Composer one for instance).
*
* // with a Symfony autoloader
* use Symfony\Component\ClassLoader\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->addPrefix('Symfony\Component', __DIR__.'/component');
* $loader->addPrefix('Symfony', __DIR__.'/framework');
*
* // register classes with namespaces
* // or with a Composer autoloader
* use Composer\Autoload\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
@@ -43,18 +51,17 @@ class WinCacheClassLoader
private $prefix;
/**
* The class loader object being decorated.
* A class loader object that implements the findFile() method.
*
* @var \Symfony\Component\ClassLoader\ClassLoader
* A class loader object that implements the findFile() method.
* @var object
*/
protected $decorated;
/**
* Constructor.
*
* @param string $prefix The WinCache namespace prefix to use.
* @param object $decorated A class loader object that implements the findFile() method.
* @param string $prefix The WinCache namespace prefix to use.
* @param object $decorated A class loader object that implements the findFile() method.
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
@@ -76,7 +83,7 @@ class WinCacheClassLoader
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -96,7 +103,7 @@ class WinCacheClassLoader
*
* @param string $class The name of the class
*
* @return bool|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{

View File

@@ -17,11 +17,19 @@ namespace Symfony\Component\ClassLoader;
* It expects an object implementing a findFile method to find the file. This
* allows using it as a wrapper around the other loaders of the component (the
* ClassLoader and the UniversalClassLoader for instance) but also around any
* other autoloader following this convention (the Composer one for instance)
* other autoloaders following this convention (the Composer one for instance).
*
* // with a Symfony autoloader
* use Symfony\Component\ClassLoader\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->addPrefix('Symfony\Component', __DIR__.'/component');
* $loader->addPrefix('Symfony', __DIR__.'/framework');
*
* // register classes with namespaces
* // or with a Composer autoloader
* use Composer\Autoload\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
@@ -37,28 +45,26 @@ namespace Symfony\Component\ClassLoader;
* @author Fabien Potencier <fabien@symfony.com>
* @author Kris Wallsmith <kris@symfony.com>
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*
* @api
*/
class XcacheClassLoader
{
private $prefix;
/**
* @var object A class loader object that implements the findFile() method
* 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.
* @param string $prefix The XCache namespace prefix to use.
* @param object $decorated A class loader object that implements the findFile() method.
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*
* @api
*/
public function __construct($prefix, $decorated)
{
@@ -77,7 +83,7 @@ class XcacheClassLoader
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -97,7 +103,7 @@ class XcacheClassLoader
*
* @param string $class The name of the class
*
* @return bool|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{

View File

@@ -3,7 +3,7 @@
"type": "library",
"description": "Symfony ClassLoader Component",
"keywords": [],
"homepage": "http://symfony.com",
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
@@ -12,7 +12,7 @@
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
"homepage": "https://symfony.com/contributors"
}
],
"minimum-stability": "dev",
@@ -20,10 +20,13 @@
"php": ">=5.3.3"
},
"require-dev": {
"symfony/finder": "~2.0"
"symfony/finder": "~2.0,>=2.0.5"
},
"autoload": {
"psr-0": { "Symfony\\Component\\ClassLoader\\": "" }
"psr-0": { "Symfony\\Component\\ClassLoader\\": "" },
"exclude-from-classmap": [
"/Tests/"
]
},
"target-dir": "Symfony/Component/ClassLoader",
"extra": {

View File

@@ -6,6 +6,10 @@
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="Symfony ClassLoader Component Test Suite">
<directory>./Tests/</directory>