Compare commits

...

83 Commits
2.2 ... v2.3.39

Author SHA1 Message Date
Nicolas Grekas
d77ac7df59 [Filesystem] Fix transient tests 2016-03-10 15:49:24 +01:00
Javier Eguiluz
355a6b3ee2 Updated all the README files 2016-03-04 08:12:06 +01:00
Fabien Potencier
ac7c135db5 fixed APCu dep version 2016-01-25 15:47:02 +01:00
Geoff
71ff8cc2af [ClassLoader] Use symfony/polyfill-apcu 2016-01-18 12:27:23 -08:00
Fabien Potencier
136d713362 bug #17377 Fix performance (PHP5) and memory (PHP7) issues when using token_get_all (nicolas-grekas, peteward)
This PR was merged into the 2.3 branch.

Discussion
----------

Fix performance (PHP5) and memory (PHP7) issues when using token_get_all

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

Although it's not the case anymore on PHP 7, on PHP 5, `is_array` checks are much slower than `isset` checks.

Also from @peteward in #17384:
>  New PHP7 memory manager will not release small buckets to OS automatically in cases exposed by `token_get_all()`. This function call addition specifically for PHP7 will reclaim this memory to keep the footprint down of long processe

> See above ticket and suggested actions by PHP internals team for long-running tasks (https://bugs.php.net/70098) - I think `cache:clear/warmup` on a heavy app justifies this.

> We're running on cloud-based hosting platforms under memory limitations (Platform.sh). When memory is exceeded we're into swap and the cache clearing process goes from seconds to minutes for the initial deployment, which really slows our development workflow and also causes holding page delays.

Commits
-------

e555aad Add gc_mem_caches() call for PHP7 after itoken_get_all() as new memory manager will not release small buckets to OS automatically
d1f72d8 Fix perf and mem issue when using token_get_all
2016-01-15 17:52:13 +01:00
Peter Ward
72df2d4535 Add gc_mem_caches() call for PHP7 after itoken_get_all() as new memory manager will not release small buckets to OS automatically 2016-01-15 10:01:44 +01:00
Nicolas Grekas
a08420fb07 [ClassLoader] Use symfony/polyfill-apcu 2016-01-14 18:42:51 +01:00
Nicolas Grekas
6dc4479622 Fix perf and mem issue when using token_get_all 2016-01-14 14:27:10 +01:00
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
Fabien Potencier
39a9bc391d fixed CS 2014-09-22 10:32:35 +02:00
Fabien Potencier
d3b0938fa2 [ClassLoader] simplified phpdoc 2014-08-28 16:35:12 +02:00
Tobias Stöckler
3acea26b17 [ClassLoader] Add a __call() method to XcacheClassLoader 2014-08-28 16:33:42 +02:00
Christian Raue
732b31a9fe removed defaults from PHPUnit configuration 2014-07-07 12:13:42 +02:00
Christian Raue
afb83252cb added XSD to PHPUnit configuration 2014-07-07 11:57:21 +02:00
Fabien Potencier
b321e4830b [ClassLoader] fixed PHP warning on PHP 5.3 2014-06-26 10:33:01 +02:00
Fabien Potencier
343414e2a5 fixed types in phpdocs 2014-04-16 12:30:19 +02:00
Fabien Potencier
e971e40b45 made {@inheritdoc} annotations consistent across the board 2014-04-16 09:04:20 +02:00
Fabien Potencier
dd8c297b91 made phpdoc types consistent with those defined in Hack 2014-04-15 07:41:45 +02:00
Fabien Potencier
26de2f175f made types consistent with those defined in Hack 2014-04-13 20:00:14 +02:00
Ioan Negulescu
142de518bf Fix class names in ApcUniversalClassLoader tests. 2014-03-29 07:58:16 +01:00
Fabien Potencier
8a70d1963f fixed various inconsistencies 2014-02-11 11:29:24 +01:00
Luis Cordova
18d1b5e575 update year on licenses 2014-01-07 08:19:25 -05:00
Fabien Potencier
181f15a84f Merge branch '2.2' into 2.3
* 2.2:
  fixed some typos
  fixed @expectedException class names

Conflicts:
	src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php
	src/Symfony/Component/Console/Tests/Command/CommandTest.php
	src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php
	src/Symfony/Component/Locale/Tests/Stub/StubNumberFormatterTest.php
2013-11-25 15:49:41 +01:00
Fabien Potencier
e5f3ef7ebd Merge branch '2.2' into 2.3
* 2.2:
  Fix some annotates
  [FrameworkBundle] made sure that the debug event dispatcher is used everywhere
  [HttpKernel] remove unneeded strtoupper
  updated the composer install command to reflect changes in Composer

Conflicts:
	src/Symfony/Component/Console/Application.php
	src/Symfony/Component/Console/Command/Command.php
	src/Symfony/Component/Console/Input/InputDefinition.php
	src/Symfony/Component/CssSelector/Node/CombinedSelectorNode.php
	src/Symfony/Component/Form/Form.php
	src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php
	src/Symfony/Component/HttpKernel/DependencyInjection/RegisterListenersPass.php
	src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterListenersPassTest.php
	src/Symfony/Component/Locale/Locale.php
	src/Symfony/Component/Locale/README.md
	src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php
2013-09-19 11:45:20 +02:00
Fabien Potencier
622d370a07 Merge branch '2.2' into 2.3
* 2.2:
  corrected English grammar (s/does not exists/does not exist)
  [Process] Add more precision to Process::stop timeout
  [Process] Avoid zombie process in case of unit tests failure
  [Process] Fix #8739
  [Process] Add failing test for #8739
  [Process] Fix CS
  Fixed documentation grammar for AuthenticationManagerInterface::authenticate()
  [Validator] fixed the wrong isAbstract() check against the class (fixed #8589)
  [TwigBridge] Prevent code extension to display warning
  Use strstr instead of strpos

Conflicts:
	src/Symfony/Component/Finder/Shell/Command.php
	src/Symfony/Component/Process/Process.php
2013-08-13 22:18:00 +02:00
Martin Hasoň
7ffb15eeff Added missing files .gitignore 2013-07-21 14:12:18 +02:00
Tobias Schultze
fa3394c6fd [ClassLoader] tiny refactoring 2013-05-24 19:54:44 +02:00
Christian Flothmann
5e53d66ce8 remove check for PHP bug #50731 2013-05-16 11:44:24 +02:00
Fabien Potencier
db283a5469 Merge branch '2.2'
* 2.2:
  bumped Symfony version to 2.1.11-DEV
  updated VERSION for 2.1.10
  update CONTRIBUTORS for 2.1.10
  updated CHANGELOG for 2.1.10
  fixed CS
  [Process] Cleanup tests & prevent assertion that kills randomly Travis-CI
  [Filesystem] Fix regression introduced in 10dea948

Conflicts:
	src/Symfony/Component/Process/Tests/AbstractProcessTest.php
2013-05-06 22:03:44 +02:00
Dariusz Górecki
d1e0a27c9c [CS Fix] Consistent coding-style of concatenation operator usage 2013-04-02 10:39:57 +01:00
Fabien Potencier
aeef488005 [ClassLoader] added missing CHANGELOG entry for previous merge 2013-03-23 09:02:48 +01:00
Fabien Potencier
44c1b7bb7c merged branch Smart-Core/master (PR #7076)
This PR was merged into the master branch.

Discussion
----------

[2.3] Add missing WinCacheClassLoader

Commits
-------

af86e5b Add missing WinCacheClassLoader
2013-03-23 09:00:58 +01:00
Fabien Potencier
8bff32cf48 Merge branch '2.2'
* 2.2: (70 commits)
  change wrapped exception message to be more usefull
  updated VERSION for 2.0.23
  update CONTRIBUTORS for 2.0.23
  updated CHANGELOG for 2.0.23
  [Form] fixed failing test
  [DomCrawler] added support for query string with slash
  Fixed invalid file path for hiddeninput.exe on Windows.
  fix xsd definition for strict-requirements
  [WebProfilerBundle] Fixed the toolbar styles to apply them in IE8
  [ClassLoader] fixed heredocs handling
  fixed handling of heredocs
  Add a public modifier to an interface method
  removing xdebug extension
  [HttpRequest] fixes Request::getLanguages() bug
  [HttpCache] added a test (cached content should be kept after purging)
  [DoctrineBridge] Fixed non-utf-8 recognition
  [Security] fixed HttpUtils class tests
  replaced new occurences of 'Request::create()' with '::create()'
  changed sub-requests creation to '::create()'
  fixed merge issue
  ...

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php
	src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig
	src/Symfony/Component/DomCrawler/Link.php
	src/Symfony/Component/Translation/Translator.php
2013-03-20 15:03:03 +01:00
Fabien Potencier
a474c6ead0 Merge branch '2.2'
* 2.2:
  fixed CS
  Add persian translation to Components/Security
  bumped Symfony version to 2.2.1-DEV-DEV
  updated VERSION for 2.2.0
  updated CHANGELOG for 2.2.0
2013-03-01 11:42:20 +01:00
Fabien Potencier
58cfa84f7d Merge branch '2.2'
* 2.2: (24 commits)
  Options small typo
  [Console] fixed unparsed StringInput tokens
  Mask PHP_AUTH_PW header in profiler
  [TwigBridge] fixed trans twig extractor
  [Finder] adds adapter selection/unselection capabilities
  [DomCrawler] fix handling of schemes by Link::getUri()
  [Console] Fixed comment
  [TwigBridge] fixed the translator extractor that were not trimming the text in trans tags (closes #7056)
  Fixed handling absent href attribute in base tag
  fixed paths/notPaths regex for shell adapters
  fix issue 4911
  Adds expandable globs support to shell adapters
  [HttpFoundation] Fixed messed up headers
  Fixes AppCache + ESI + Stopwatch problem
  added a DebuClassLoader::findFile() method to make the wrapping less invasive
  bumped Symfony version to 2.2.0-RC4-DEV
  updated VERSION for 2.2.0-RC3
  updated CHANGELOG for 2.2.0-RC3
  fixed CHANGELOG
  bumped Symfony version to 2.1.9-DEV
  ...
2013-03-01 07:43:27 +01:00
Smart-Core
e69dbce5e1 Add missing WinCacheClassLoader 2013-02-15 05:40:51 +07:00
Fabien Potencier
d482b15c7a Merge branch '2.2'
* 2.2: (30 commits)
  [HttpFoundation] Added support for partial ranges in the BinaryFileResponse.
  [HttpFoundation] Fixed byte ranges in the BinaryFileResponse.
  updated required versions when depending on the HttpFoundation component
  updated required versions when depending on the HttpKernel component
  updated required versions when depending on the Config component
  updated required versions when depending on the Form component
  updated required versions when depending on the DependencyInjection component
  updated required versions when depending on the Validator component
  updated required versions when depending on the Translation component
  updated required versions when depending on the Routing component
  updated required versions when depending on the EventDispatcher component
  updated required versions when depending on the OptionsResolver component
  updated required versions when depending on the PropertyAccess component
  updated required versions when depending on the Security component
  updated required versions when depending on the Templating component
  updated required versions when depending on the Stopwatch component
  updated required versions when depending on the Process component
  updated required versions when depending on the Finder component
  updated required versions when depending on the Dom Crawler component
  use ~2.0 when depending on the Dom Crawler component
  ...
2013-02-11 11:09:44 +01:00
Fabien Potencier
f7c749435b Merge branch '2.2'
* 2.2:
  fixed regression in the Finder component (it was possible to use it without using exec before, closes #6357)
  fixed a circular call (closes #6864)
  typo
  [Security] [Tests] added unit tests for the UserPasswordValidator class and made the validator service for the UserPassword constraint configurable.
  fixed wrong indentation
  tweaked previous commit
  [HttpKernel] Fix the URI signer (closes #6801)
  Add Arabic translations.
  [HttpKernel] fixed regression when rendering an inline controller and passing some objects  (closes #6822)
  [FrameworkBundle] fixed typo
  renamed some classes and Twig functions to more descriptive names (refs #6871)
  Classcollectionloader: fix traits + enhancements
  Fix a deprecated method call in the tests
  Update `composer.json` files: - to allow versions ~2.2 (>=2.2,<3.0) of Doctrine DBAL, ORM & Common - fixed Propel1 versions difference between main and bridge files - fixed Twig versions difference between main and bridge files - to allow versions ~1.11 (>=1.11,<2.0) of Twig - fixed Locale ext-intl version to accept all, not non-existing version
  Correct comment in NativeSessionStorage regarding session.save_handler
  [Security] Add PHPDoc to AuthenticationEvents
2013-02-04 13:42:02 +01:00
Fabien Potencier
50b9d9501e updated the branch alias in composer files 2013-01-31 22:39:01 +01:00
35 changed files with 547 additions and 347 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,3 @@
vendor/
composer.lock
phpunit.xml

View File

@@ -15,13 +15,21 @@ namespace Symfony\Component\ClassLoader;
* ApcClassLoader implements a wrapping autoloader cached in APC for PHP 5.3.
*
* It expects an object implementing a findFile method to find the file. This
* allow using it as a wrapper around the other loaders of the component (the
* allows using it as a wrapper around the other loaders of the component (the
* ClassLoader and the UniversalClassLoader for instance) but also around any
* other autoloader following this convention (the Composer one for instance)
* other autoloaders following this convention (the Composer one for instance).
*
* // with a Symfony autoloader
* use Symfony\Component\ClassLoader\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->addPrefix('Symfony\Component', __DIR__.'/component');
* $loader->addPrefix('Symfony', __DIR__.'/framework');
*
* // register classes with namespaces
* // or with a Composer autoloader
* use Composer\Autoload\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
@@ -36,36 +44,31 @@ 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 \Symfony\Component\ClassLoader\ClassLoader
* A class loader object that implements the findFile() method.
* @var object
*/
protected $decorated;
/**
* Constructor.
*
* @param string $prefix The APC namespace prefix to use.
* @param object $decorated A class loader object that implements the findFile() method.
* @param string $prefix The APC namespace prefix to use.
* @param object $decorated A class loader object that implements the findFile() method.
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*
* @api
*/
public function __construct($prefix, $decorated)
{
if (!extension_loaded('apc')) {
throw new \RuntimeException('Unable to use ApcClassLoader as APC is not enabled.');
if (!function_exists('apcu_fetch')) {
throw new \RuntimeException('Unable to use ApcClassLoader as APC is not installed.');
}
if (!method_exists($decorated, 'findFile')) {
@@ -79,7 +82,7 @@ class ApcClassLoader
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -99,7 +102,7 @@ class ApcClassLoader
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
@@ -119,8 +122,8 @@ class ApcClassLoader
*/
public function findFile($class)
{
if (false === $file = apc_fetch($this->prefix.$class)) {
apc_store($this->prefix.$class, $file = $this->decorated->findFile($class));
if (false === $file = apcu_fetch($this->prefix.$class)) {
apcu_store($this->prefix.$class, $file = $this->decorated->findFile($class));
}
return $file;
@@ -133,5 +136,4 @@ class ApcClassLoader
{
return call_user_func_array(array($this->decorated, $method), $args);
}
}

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,12 +68,10 @@ class ApcUniversalClassLoader extends UniversalClassLoader
* @param string $prefix A prefix to create a namespace in APC
*
* @throws \RuntimeException
*
* @api
*/
public function __construct($prefix)
{
if (!extension_loaded('apc')) {
if (!function_exists('apcu_fetch')) {
throw new \RuntimeException('Unable to use ApcUniversalClassLoader as APC is not enabled.');
}
@@ -91,8 +87,8 @@ class ApcUniversalClassLoader extends UniversalClassLoader
*/
public function findFile($class)
{
if (false === $file = apc_fetch($this->prefix.$class)) {
apc_store($this->prefix.$class, $file = parent::findFile($class));
if (false === $file = apcu_fetch($this->prefix.$class)) {
apcu_store($this->prefix.$class, $file = parent::findFile($class));
}
return $file;

View File

@@ -1,6 +1,11 @@
CHANGELOG
=========
2.3.0
-----
* added a WinCacheClassLoader for WinCache
2.1.0
-----

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 Boolean $autoReload Whether to flush the cache when the cache is stale or not
* @param Boolean $adaptive Whether to remove already declared classes or not
* @param string $extension File extension of the resulting file
* @param array $classes An array of classes to load
* @param string $cacheDir A cache directory
* @param string $name The cache name prefix
* @param bool $autoReload Whether to flush the cache when the cache is stale or not
* @param bool $adaptive Whether to remove already declared classes or not
* @param string $extension File extension of the resulting file
*
* @throws \InvalidArgumentException When class can't be loaded
*/
@@ -63,7 +63,7 @@ class ClassCollectionLoader
// auto-reload
$reload = false;
if ($autoReload) {
$metadata = $cacheDir.'/'.$name.$extension.'.meta';
$metadata = $cache.'.meta';
if (!is_file($metadata) || !is_file($cache)) {
$reload = true;
} else {
@@ -116,8 +116,8 @@ class ClassCollectionLoader
}
// cache the core classes
if (!is_dir(dirname($cache))) {
mkdir(dirname($cache), 0777, true);
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
}
self::writeCacheFile($cache, '<?php '.$content);
@@ -137,8 +137,8 @@ class ClassCollectionLoader
public static function fixNamespaceDeclarations($source)
{
if (!function_exists('token_get_all') || !self::$useTokenizer) {
if (preg_match('/namespace(.*?)\s*;/', $source)) {
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
if (preg_match('/(^|\s)namespace(.*?)\s*;/', $source)) {
$source = preg_replace('/(^|\s)namespace(.*?)\s*;/', "$1namespace$2\n{", $source)."}\n";
}
return $source;
@@ -149,8 +149,9 @@ class ClassCollectionLoader
$inNamespace = false;
$tokens = token_get_all($source);
for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
if (is_string($token)) {
for ($i = 0; isset($tokens[$i]); ++$i) {
$token = $tokens[$i];
if (!isset($token[1]) || 'b"' === $token) {
$rawChunk .= $token;
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
// strip comments
@@ -162,12 +163,12 @@ class ClassCollectionLoader
$rawChunk .= $token[1];
// namespace name and whitespaces
while (($t = next($tokens)) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
$rawChunk .= $t[1];
while (isset($tokens[++$i][1]) && in_array($tokens[$i][0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
$rawChunk .= $tokens[$i][1];
}
if ('{' === $t) {
if ('{' === $tokens[$i]) {
$inNamespace = false;
prev($tokens);
--$i;
} else {
$rawChunk = rtrim($rawChunk)."\n{";
$inNamespace = true;
@@ -175,8 +176,8 @@ class ClassCollectionLoader
} elseif (T_START_HEREDOC === $token[0]) {
$output .= self::compressCode($rawChunk).$token[1];
do {
$token = next($tokens);
$output .= is_string($token) ? $token : $token[1];
$token = $tokens[++$i];
$output .= isset($token[1]) && 'b"' !== $token ? $token[1] : $token;
} while ($token[0] !== T_END_HEREDOC);
$output .= "\n";
$rawChunk = '';
@@ -192,7 +193,15 @@ class ClassCollectionLoader
$rawChunk .= "}\n";
}
return $output.self::compressCode($rawChunk);
$output .= self::compressCode($rawChunk);
if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
unset($tokens, $rawChunk);
gc_mem_caches();
}
return $output;
}
/**
@@ -200,7 +209,7 @@ class ClassCollectionLoader
*/
public static function enableTokenizer($bool)
{
self::$useTokenizer = (Boolean) $bool;
self::$useTokenizer = (bool) $bool;
}
/**
@@ -283,7 +292,7 @@ class ClassCollectionLoader
$traits = array();
if (function_exists('get_declared_traits')) {
if (method_exists('ReflectionClass', 'getTraits')) {
foreach ($classes as $c) {
foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
if ($trait !== $c) {
@@ -335,10 +344,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 +362,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,30 +91,34 @@ 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 Boolean $useIncludePath
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
$this->useIncludePath = (bool) $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return Boolean
* @return bool
*/
public function getUseIncludePath()
{
@@ -124,7 +128,7 @@ class ClassLoader
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -144,7 +148,7 @@ class ClassLoader
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
@@ -164,13 +168,9 @@ class ClassLoader
*/
public function findFile($class)
{
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
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,21 +178,21 @@ 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;
}
}

View File

@@ -11,15 +11,23 @@
namespace Symfony\Component\ClassLoader;
if (!defined('SYMFONY_TRAIT')) {
if (PHP_VERSION_ID >= 50400) {
define('SYMFONY_TRAIT', T_TRAIT);
} else {
define('SYMFONY_TRAIT', 0);
}
}
/**
* ClassMapGenerator
* ClassMapGenerator.
*
* @author Gyula Sallai <salla016@gmail.com>
*/
class ClassMapGenerator
{
/**
* Generate a class map file
* Generate a class map file.
*
* @param array|string $dirs Directories or a single path to search in
* @param string $file The name of the class map file
@@ -37,7 +45,7 @@ class ClassMapGenerator
}
/**
* Iterate over all files in the given directory searching for classes
* Iterate over all files in the given directory searching for classes.
*
* @param \Iterator|string $dir The directory to search in or an iterator
*
@@ -64,17 +72,21 @@ class ClassMapGenerator
$classes = self::findClasses($path);
if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}
foreach ($classes as $class) {
$map[$class] = $path;
}
}
return $map;
}
/**
* Extract the classes in the given file
* Extract the classes in the given file.
*
* @param string $path The file to check
*
@@ -83,16 +95,15 @@ class ClassMapGenerator
private static function findClasses($path)
{
$contents = file_get_contents($path);
$tokens = token_get_all($contents);
$T_TRAIT = version_compare(PHP_VERSION, '5.4', '<') ? -1 : T_TRAIT;
$tokens = token_get_all($contents);
$classes = array();
$namespace = '';
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
for ($i = 0; isset($tokens[$i]); ++$i) {
$token = $tokens[$i];
if (is_string($token)) {
if (!isset($token[1])) {
continue;
}
@@ -102,26 +113,46 @@ class ClassMapGenerator
case T_NAMESPACE:
$namespace = '';
// If there is a namespace, extract it
while (($t = $tokens[++$i]) && is_array($t)) {
if (in_array($t[0], array(T_STRING, T_NS_SEPARATOR))) {
$namespace .= $t[1];
while (isset($tokens[++$i][1])) {
if (in_array($tokens[$i][0], array(T_STRING, T_NS_SEPARATOR))) {
$namespace .= $tokens[$i][1];
}
}
$namespace .= '\\';
break;
case T_CLASS:
case T_INTERFACE:
case $T_TRAIT:
// Find the classname
while (($t = $tokens[++$i]) && is_array($t)) {
if (T_STRING === $t[0]) {
$class .= $t[1];
} elseif ($class !== '' && T_WHITESPACE == $t[0]) {
case SYMFONY_TRAIT:
// Skip usage of ::class constant
$isClassConstant = false;
for ($j = $i - 1; $j > 0; --$j) {
if (!isset($tokens[$j][1])) {
break;
}
if (T_DOUBLE_COLON === $tokens[$j][0]) {
$isClassConstant = true;
break;
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
break;
}
}
$classes[] = ltrim($namespace . $class, '\\');
if ($isClassConstant) {
break;
}
// Find the classname
while (isset($tokens[++$i][1])) {
$t = $tokens[$i];
if (T_STRING === $t[0]) {
$class .= $t[1];
} elseif ('' !== $class && T_WHITESPACE === $t[0]) {
break;
}
}
$classes[] = ltrim($namespace.$class, '\\');
break;
default:
break;

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 Boolean|null True, if loaded
* @return bool|null True, if loaded
*
* @throws \RuntimeException
*/

View File

@@ -48,7 +48,7 @@ class DebugUniversalClassLoader extends UniversalClassLoader
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function loadClass($class)
{

View File

@@ -1,4 +1,4 @@
Copyright (c) 2004-2013 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 Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -47,10 +47,6 @@ class MapClassLoader
*/
public function loadClass($class)
{
if ('\\' === $class[0]) {
$class = substr($class, 1);
}
if (isset($this->map[$class])) {
require $this->map[$class];
}
@@ -65,10 +61,6 @@ class MapClassLoader
*/
public function findFile($class)
{
if ('\\' === $class[0]) {
$class = substr($class, 1);
}
if (isset($this->map[$class])) {
return $this->map[$class];
}

View File

@@ -1,69 +1,14 @@
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
standard or the PEAR naming convention.
First, register the autoloader:
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->register();
Then, register some namespaces with the `registerNamespace()` method:
$loader->registerNamespace('Symfony', __DIR__.'/src');
$loader->registerNamespace('Monolog', __DIR__.'/vendor/monolog/src');
The `registerNamespace()` 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');
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'));
Alternatively, you can use the `registerNamespaces()` 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',
));
For better performance, you can use the APC based version of the universal
class loader:
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
$loader = new ApcUniversalClassLoader('apc.prefix.');
Furthermore, the component provides tools to aggregate classes into a single
file, which is especially useful to improve performance on servers that do not
provide byte caches.
The ClassLoader component provides tools to autoload your classes and cache
their locations for performance.
Resources
---------
You can run the unit tests with the following command:
$ cd path/to/Symfony/Component/ClassLoader/
$ composer.phar install
$ phpunit
* [Documentation](https://symfony.com/doc/current/components/class_loader/index.html)
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
* [Report issues](https://github.com/symfony/symfony/issues) and
[send Pull Requests](https://github.com/symfony/symfony/pulls)
in the [main Symfony repository](https://github.com/symfony/symfony)

View File

@@ -17,21 +17,17 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!extension_loaded('apc')) {
$this->markTestSkipped('The apc extension is not available.');
}
if (!(ini_get('apc.enabled') && ini_get('apc.enable_cli'))) {
$this->markTestSkipped('The apc extension is available, but not enabled.');
if (ini_get('apc.enabled') && ini_get('apc.enable_cli')) {
apcu_clear_cache();
} else {
apc_clear_cache('user');
$this->markTestSkipped('APC is not enabled.');
}
}
protected function tearDown()
{
if (ini_get('apc.enabled') && ini_get('apc.enable_cli')) {
apc_clear_cache('user');
apcu_clear_cache();
}
}
@@ -40,7 +36,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
$loader = new ApcUniversalClassLoader('test.prefix.');
$loader->registerNamespace('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
$this->assertEquals($loader->findFile('\Apc\Namespaced\FooBar'), apc_fetch('test.prefix.\Apc\Namespaced\FooBar'), '__construct() takes a prefix as its first argument');
$this->assertEquals($loader->findFile('\Apc\Namespaced\FooBar'), apcu_fetch('test.prefix.\Apc\Namespaced\FooBar'), '__construct() takes a prefix as its first argument');
}
/**
@@ -55,15 +51,13 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(class_exists($className), $message);
}
public function getLoadClassTests()
{
return array(
array('\\Apc\\Namespaced\\Foo', '\\Apc\\Namespaced\\Foo', '->loadClass() loads Apc\Namespaced\Foo class'),
public function getLoadClassTests()
{
return array(
array('\\Apc\\Namespaced\\Foo', 'Apc\\Namespaced\\Foo', '->loadClass() loads Apc\Namespaced\Foo class'),
array('Apc_Pearlike_Foo', 'Apc_Pearlike_Foo', '->loadClass() loads Apc_Pearlike_Foo class'),
array('\\Apc\\Namespaced\\Bar', '\\Apc\\Namespaced\\Bar', '->loadClass() loads Apc\Namespaced\Bar class with a leading slash'),
array('Apc_Pearlike_Bar', '\\Apc_Pearlike_Bar', '->loadClass() loads Apc_Pearlike_Bar class with a leading slash'),
);
}
}
/**
* @dataProvider getLoadClassFromFallbackTests
@@ -79,15 +73,15 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(class_exists($className), $message);
}
public function getLoadClassFromFallbackTests()
{
return array(
array('\\Apc\\Namespaced\\Baz', '\\Apc\\Namespaced\\Baz', '->loadClass() loads Apc\Namespaced\Baz class'),
public function getLoadClassFromFallbackTests()
{
return array(
array('\\Apc\\Namespaced\\Baz', 'Apc\\Namespaced\\Baz', '->loadClass() loads Apc\Namespaced\Baz class'),
array('Apc_Pearlike_Baz', 'Apc_Pearlike_Baz', '->loadClass() loads Apc_Pearlike_Baz class'),
array('\\Apc\\Namespaced\\FooBar', '\\Apc\\Namespaced\\FooBar', '->loadClass() loads Apc\Namespaced\Baz class from fallback dir'),
array('\\Apc\\Namespaced\\FooBar', 'Apc\\Namespaced\\FooBar', '->loadClass() loads Apc\Namespaced\Baz class from fallback dir'),
array('Apc_Pearlike_FooBar', 'Apc_Pearlike_FooBar', '->loadClass() loads Apc_Pearlike_Baz class from fallback dir'),
);
}
}
/**
* @dataProvider getLoadClassNamespaceCollisionTests
@@ -102,15 +96,15 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(class_exists($className), $message);
}
public function getLoadClassNamespaceCollisionTests()
{
return array(
public function getLoadClassNamespaceCollisionTests()
{
return array(
array(
array(
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
),
'\Apc\NamespaceCollision\A\Foo',
'Apc\NamespaceCollision\A\Foo',
'->loadClass() loads NamespaceCollision\A\Foo from alpha.',
),
array(
@@ -118,7 +112,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
),
'\Apc\NamespaceCollision\A\Bar',
'Apc\NamespaceCollision\A\Bar',
'->loadClass() loads NamespaceCollision\A\Bar from alpha.',
),
array(
@@ -126,7 +120,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
),
'\Apc\NamespaceCollision\A\B\Foo',
'Apc\NamespaceCollision\A\B\Foo',
'->loadClass() loads NamespaceCollision\A\B\Foo from beta.',
),
array(
@@ -134,11 +128,11 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
),
'\Apc\NamespaceCollision\A\B\Bar',
'Apc\NamespaceCollision\A\B\Bar',
'->loadClass() loads NamespaceCollision\A\B\Bar from beta.',
),
);
}
}
/**
* @dataProvider getLoadClassPrefixCollisionTests
@@ -152,9 +146,9 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(class_exists($className), $message);
}
public function getLoadClassPrefixCollisionTests()
{
return array(
public function getLoadClassPrefixCollisionTests()
{
return array(
array(
array(
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
@@ -188,5 +182,5 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
'->loadClass() loads ApcPrefixCollision_A_B_Bar from beta.',
),
);
}
}
}

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

@@ -54,8 +54,6 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
return array(
array('\\Namespaced2\\Foo', 'Namespaced2\\Foo', '->loadClass() loads Namespaced2\Foo class'),
array('\\Pearlike2_Foo', 'Pearlike2_Foo', '->loadClass() loads Pearlike2_Foo class'),
array('\\Namespaced2\\Bar', '\\Namespaced2\\Bar', '->loadClass() loads Namespaced2\Bar class with a leading slash'),
array('\\Pearlike2_Bar', '\\Pearlike2_Bar', '->loadClass() loads Pearlike2_Bar class with a leading slash'),
);
}
@@ -78,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()
@@ -100,7 +120,7 @@ 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'));

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 = sys_get_temp_dir().'/'.microtime(true).'.'.mt_rand();
mkdir($this->workspace, 0777, true);
$this->workspace = realpath($this->workspace);
}
@@ -47,7 +47,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider getTestCreateMapTests
*/
public function testDump($directory, $expected)
public function testDump($directory)
{
$this->prepare_workspace();
@@ -72,11 +72,11 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
{
$data = array(
array(__DIR__.'/Fixtures/Namespaced', array(
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.php',
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.php',
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
'Namespaced\\WithComments' => realpath(__DIR__).'/Fixtures/Namespaced/WithComments.php',
)
),
),
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array(
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
@@ -85,26 +85,26 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
'NamespaceCollision\\C\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Foo.php',
)),
array(__DIR__.'/Fixtures/Pearlike', array(
'Pearlike_Foo' => realpath(__DIR__).'/Fixtures/Pearlike/Foo.php',
'Pearlike_Bar' => realpath(__DIR__).'/Fixtures/Pearlike/Bar.php',
'Pearlike_Baz' => realpath(__DIR__).'/Fixtures/Pearlike/Baz.php',
'Pearlike_Foo' => realpath(__DIR__).'/Fixtures/Pearlike/Foo.php',
'Pearlike_Bar' => realpath(__DIR__).'/Fixtures/Pearlike/Bar.php',
'Pearlike_Baz' => realpath(__DIR__).'/Fixtures/Pearlike/Baz.php',
'Pearlike_WithComments' => realpath(__DIR__).'/Fixtures/Pearlike/WithComments.php',
)),
array(__DIR__.'/Fixtures/classmap', array(
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Beta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Beta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php',
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
)),
);
if (version_compare(PHP_VERSION, '5.4', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
@@ -115,17 +115,19 @@ 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');
$finder->files()->in(__DIR__.'/Fixtures/beta/NamespaceCollision');
$this->assertEqualsNormalized(array(
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
@@ -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

@@ -2,4 +2,6 @@
namespace ClassesWithParents;
class A extends B {}
class A extends B
{
}

View File

@@ -2,4 +2,6 @@
namespace ClassesWithParents;
class B implements CInterface {}
class B implements CInterface
{
}

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

@@ -13,5 +13,4 @@ namespace ClassMap;
class SomeClass extends SomeParent implements SomeInterface
{
}

View File

@@ -13,5 +13,4 @@ namespace ClassMap;
interface SomeInterface
{
}

View File

@@ -13,5 +13,4 @@ namespace ClassMap;
abstract class SomeParent
{
}

View File

@@ -1,14 +1,25 @@
<?php
namespace {
class A {}
class A
{
}
}
namespace Alpha {
class A {}
class B {}
class A
{
}
class B
{
}
}
namespace Beta {
class A {}
class B {}
class A
{
}
class B
{
}
}

View File

@@ -11,5 +11,9 @@
namespace Foo\Bar;
class A {}
class B {}
class A
{
}
class B
{
}

View File

@@ -1,7 +1,8 @@
<?php
trait TD
{}
{
}
trait TZ
{

View File

@@ -1,4 +1,5 @@
<?php
namespace {
trait TFoo
{
@@ -25,6 +26,7 @@ namespace Foo {
class CBar implements IBar
{
use TBar, TFooBar;
use TBar;
use TFooBar;
}
}

View File

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

View File

@@ -32,8 +32,6 @@ class UniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
return array(
array('\\Namespaced\\Foo', 'Namespaced\\Foo', '->loadClass() loads Namespaced\Foo class'),
array('\\Pearlike_Foo', 'Pearlike_Foo', '->loadClass() loads Pearlike_Foo class'),
array('\\Namespaced\\Bar', '\\Namespaced\\Bar', '->loadClass() loads Namespaced\Bar class with a leading slash'),
array('\\Pearlike_Bar', '\\Pearlike_Bar', '->loadClass() loads Pearlike_Bar class with a leading slash'),
);
}
@@ -49,7 +47,7 @@ class UniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
$loader->useIncludePath(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'));

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,20 +66,20 @@ class UniversalClassLoader
/**
* Turns on searching the include for class files. Allows easy loading
* of installed PEAR packages
* of installed PEAR packages.
*
* @param Boolean $useIncludePath
* @param bool $useIncludePath
*/
public function useIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
$this->useIncludePath = (bool) $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return Boolean
* @return bool
*/
public function getUseIncludePath()
{
@@ -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 Boolean $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 Boolean|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
@@ -263,10 +247,6 @@ class UniversalClassLoader
*/
public function findFile($class)
{
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$namespace = substr($class, 0, $pos);
@@ -291,7 +271,6 @@ class UniversalClassLoader
return $file;
}
}
} else {
// PEAR-like class name
$normalizedClass = str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';

140
WinCacheClassLoader.php Normal file
View File

@@ -0,0 +1,140 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\ClassLoader;
/**
* WinCacheClassLoader implements a wrapping autoloader cached in WinCache.
*
* 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 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');
*
* // or with a Composer autoloader
* use Composer\Autoload\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* $cachedLoader = new WinCacheClassLoader('my_prefix', $loader);
*
* // activate the cached autoloader
* $cachedLoader->register();
*
* // eventually deactivate the non-cached loader if it was registered previously
* // to be sure to use the cached one.
* $loader->unregister();
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Kris Wallsmith <kris@symfony.com>
* @author Artem Ryzhkov <artem@smart-core.org>
*/
class WinCacheClassLoader
{
private $prefix;
/**
* 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.
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*/
public function __construct($prefix, $decorated)
{
if (!extension_loaded('wincache')) {
throw new \RuntimeException('Unable to use WinCacheClassLoader as WinCache is not enabled.');
}
if (!method_exists($decorated, 'findFile')) {
throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
}
$this->prefix = $prefix;
$this->decorated = $decorated;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
*
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
require $file;
return true;
}
}
/**
* Finds a file by class name while caching lookups to WinCache.
*
* @param string $class A class name to resolve to file
*
* @return string|null
*/
public function findFile($class)
{
if (false === $file = wincache_ucache_get($this->prefix.$class)) {
wincache_ucache_set($this->prefix.$class, $file = $this->decorated->findFile($class), 0);
}
return $file;
}
/**
* Passes through all unknown calls onto the decorated object.
*/
public function __call($method, $args)
{
return call_user_func_array(array($this->decorated, $method), $args);
}
}

View File

@@ -12,16 +12,24 @@
namespace Symfony\Component\ClassLoader;
/**
* XcacheClassLoader implements a wrapping autoloader cached in Xcache for PHP 5.3.
* XcacheClassLoader implements a wrapping autoloader cached in XCache for PHP 5.3.
*
* It expects an object implementing a findFile method to find the file. This
* allows using it as a wrapper around the other loaders of the component (the
* ClassLoader and the UniversalClassLoader for instance) but also around any
* other autoloader following this convention (the Composer one for instance)
* other autoloaders following this convention (the Composer one for instance).
*
* // with a Symfony autoloader
* use Symfony\Component\ClassLoader\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->addPrefix('Symfony\Component', __DIR__.'/component');
* $loader->addPrefix('Symfony', __DIR__.'/framework');
*
* // register classes with namespaces
* // or with a Composer autoloader
* use Composer\Autoload\ClassLoader;
*
* $loader = new ClassLoader();
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
@@ -37,43 +45,45 @@ 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;
private $classFinder;
/**
* A class loader object that implements the findFile() method.
*
* @var object
*/
private $decorated;
/**
* Constructor.
*
* @param string $prefix A prefix to create a namespace in Xcache
* @param object $classFinder An object that implements findFile() method.
* @param string $prefix The XCache namespace prefix to use.
* @param object $decorated A class loader object that implements the findFile() method.
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*
* @api
*/
public function __construct($prefix, $classFinder)
public function __construct($prefix, $decorated)
{
if (!extension_loaded('Xcache')) {
throw new \RuntimeException('Unable to use XcacheClassLoader as Xcache is not enabled.');
if (!extension_loaded('xcache')) {
throw new \RuntimeException('Unable to use XcacheClassLoader as XCache is not enabled.');
}
if (!method_exists($classFinder, 'findFile')) {
if (!method_exists($decorated, 'findFile')) {
throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
}
$this->prefix = $prefix;
$this->classFinder = $classFinder;
$this->decorated = $decorated;
}
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -93,7 +103,7 @@ class XcacheClassLoader
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
@@ -116,9 +126,18 @@ class XcacheClassLoader
if (xcache_isset($this->prefix.$class)) {
$file = xcache_get($this->prefix.$class);
} else {
xcache_set($this->prefix.$class, $file = $this->classFinder->findFile($class));
$file = $this->decorated->findFile($class);
xcache_set($this->prefix.$class, $file);
}
return $file;
}
/**
* Passes through all unknown calls onto the decorated object.
*/
public function __call($method, $args)
{
return call_user_func_array(array($this->decorated, $method), $args);
}
}

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,23 +12,27 @@
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
"homepage": "https://symfony.com/contributors"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.3"
"php": ">=5.3.3",
"symfony/polyfill-apcu": "~1.1"
},
"require-dev": {
"symfony/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": {
"branch-alias": {
"dev-master": "2.2-dev"
"dev-master": "2.3-dev"
}
}
}

View File

@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="Symfony ClassLoader Component Test Suite">
<directory>./Tests/</directory>