Compare commits

...

17 Commits
v2.1.0 ... 2.1

Author SHA1 Message Date
Fabien Potencier
0e9d7c1215 fixed CS 2013-05-06 12:48:41 +02:00
Tim Nagel
05639e1018 Fixed test to use Reflection 2013-03-08 15:45:32 +11:00
Kris Wallsmith
4288c63972 [ClassLoader] tweaked test 2013-03-03 08:31:27 -08:00
Kris Wallsmith
bdb7ba2680 [ClassLoader] made DebugClassLoader idempotent 2013-03-02 11:24:53 -08:00
Fabien Potencier
4bb4dbfbaf merged branch lsmith77/debugclassloader_findfile_2_1 (PR #7168)
This PR was merged into the 2.1 branch.

Commits
-------

0690709 added a DebuClassLoader::findFile() method to make the wrapping less invasive

Discussion
----------

added a DebuClassLoader::findFile() method to make the wrapping less invasive

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

i have classified it as a bug fix, since due to the wrapping it can break assumptions about the loaded class loader, so implementing this method at least doesnt break the assumption that ``findFile()`` is available.

actually i think we should also introduced a loader interface to reduce the duct typing

---------------------------------------------------------------------------

by stof at 2013-02-24T16:39:46Z

👎 for the interface:

- it would make the use of the autoloader more difficult (you would have to require the interface before requiring the loader)
- it would forbid using these wrappers with the composer ClassLoader

---------------------------------------------------------------------------

by digitalkaoz at 2013-02-24T19:16:36Z

mh, i think all autoloaders should follow a common interface, maybe its worth to think about a PSR?

---------------------------------------------------------------------------

by lsmith77 at 2013-02-24T19:27:27Z

ah I see

---------------------------------------------------------------------------

by stof at 2013-02-24T20:33:07Z

@digitalkaoz Such an interface would have to be in PHP itself, otherwise, you would have to require it first each time (as it cannot be autoloaded before registering the autoloader). And an autoloader in PHP is just a callable.

---------------------------------------------------------------------------

by digitalkaoz at 2013-02-24T20:47:10Z

Yes @stof, i know, but it would be nice if all autoloaders follows a common pattern , call it a convention ;)
2013-02-27 08:22:37 +01:00
Lukas Kahwe Smith
4d67fd0211 added a DebuClassLoader::findFile() method to make the wrapping less invasive 2013-02-24 16:51:26 +01:00
Xavier Amado
093e495498 Fixed missing class argument when throwing exception 2013-01-26 08:21:53 +01:00
Christophe Coevoet
3f23850c82 Added an error message in the DebugClassLoader when using / instead of \. 2013-01-19 08:47:26 +01:00
Fabien Potencier
585c3e06bf removed the .gitattributes files (closes #6605, reverts #5674) 2013-01-09 09:51:07 +01:00
Fabien Potencier
28fcb90894 Merge branch '2.0' into 2.1
* 2.0:
  updated license year
  Update src/Symfony/Component/HttpFoundation/Response.php
  [Console] fixed unitialized properties (closes #5935)
  [Bundle] [FrameworkBundle] fixed typo in phpdoc of the SessionListener.
  bumped Symfony version to 2.0.21-DEV
  updated VERSION for 2.0.21
  updated CHANGELOG for 2.0.21

Conflicts:
	src/Symfony/Bundle/SwiftmailerBundle/LICENSE
	src/Symfony/Component/Filesystem/LICENSE
	src/Symfony/Component/HttpFoundation/Response.php
	src/Symfony/Component/HttpKernel/Kernel.php
2013-01-04 18:00:54 +01:00
Fabien Potencier
3527a2b300 updated license year 2013-01-04 17:59:43 +01:00
Martin Hasoň
097c9cadb8 Removed useless branch alias for dev-master in composer.json 2012-12-06 11:00:55 +01:00
Włodzimierz Gajda
29e26e8a3d Fix export-ignore on Windows 2012-11-08 10:51:48 +01:00
Fabien Potencier
d095c397b0 Merge branch '2.0' into 2.1
* 2.0:
  [ClassLoader] fixed unbracketed namespaces (closes #5747)

Conflicts:
	src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
	tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php
2012-10-27 17:59:21 +02:00
Fabien Potencier
c393e86a03 [ClassLoader] fixed unbracketed namespaces (closes #5747) 2012-10-27 17:55:46 +02:00
Igor Wiedler
1de4a18fa9 [2.1] Exclude tests from zips via gitattributes 2012-10-04 17:17:57 +02:00
Fabien Potencier
475b92bd71 fixed CS (mainly method signatures) 2012-07-09 14:43:50 +02:00
6 changed files with 110 additions and 53 deletions

View File

@@ -20,6 +20,7 @@ class ClassCollectionLoader
{
private static $loaded;
private static $seen;
private static $useTokenizer = true;
/**
* Loads a list of classes and caches them in one big file.
@@ -135,7 +136,11 @@ class ClassCollectionLoader
*/
public static function fixNamespaceDeclarations($source)
{
if (!function_exists('token_get_all')) {
if (!function_exists('token_get_all') || !self::$useTokenizer) {
if (preg_match('/namespace(.*?)\s*;/', $source)) {
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
}
return $source;
}
@@ -317,4 +322,12 @@ class ClassCollectionLoader
return $classes;
}
/**
* This method is only useful for testing.
*/
public static function enableTokenizer($bool)
{
self::$useTokenizer = (Boolean) $bool;
}
}

View File

@@ -53,7 +53,7 @@ class DebugClassLoader
}
foreach ($functions as $function) {
if (is_array($function) && method_exists($function[0], 'findFile')) {
if (is_array($function) && !$function[0] instanceof self && method_exists($function[0], 'findFile')) {
$function = array(new static($function[0]), 'loadClass');
}
@@ -69,6 +69,18 @@ class DebugClassLoader
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Finds a file by class name
*
* @param string $class A class name to resolve to file
*
* @return string|null
*/
public function findFile($class)
{
return $this->classFinder->findFile($class);
}
/**
* Loads the given class or interface.
*
@@ -82,6 +94,10 @@ class DebugClassLoader
require $file;
if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
if (false !== strpos($class, '/')) {
throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/".', $class));
}
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}

View File

@@ -1,4 +1,4 @@
Copyright (c) 2004-2012 Fabien Potencier
Copyright (c) 2004-2013 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

@@ -117,53 +117,34 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
);
}
public function testFixNamespaceDeclarations()
/**
* @dataProvider getFixNamespaceDeclarationsData
*/
public function testFixNamespaceDeclarations($source, $expected)
{
$source = <<<EOF
<?php
$this->assertEquals('<?php '.$expected, ClassCollectionLoader::fixNamespaceDeclarations('<?php '.$source));
}
namespace Foo;
class Foo {}
namespace Bar ;
class Foo {}
namespace Foo\Bar;
class Foo {}
namespace Foo\Bar\Bar
{
class Foo {}
}
namespace
{
class Foo {}
}
EOF;
/**
* @dataProvider getFixNamespaceDeclarationsData
*/
public function testFixNamespaceDeclarationsWithoutTokenizer($source, $expected)
{
ClassCollectionLoader::enableTokenizer(false);
$this->assertEquals('<?php '.$expected, ClassCollectionLoader::fixNamespaceDeclarations('<?php '.$source));
ClassCollectionLoader::enableTokenizer(true);
}
$expected = <<<EOF
<?php
namespace Foo
{
class Foo {}
}
namespace Bar
{
class Foo {}
}
namespace Foo\Bar
{
class Foo {}
}
namespace Foo\Bar\Bar
{
class Foo {}
}
namespace
{
class Foo {}
}
EOF;
$this->assertEquals($expected, ClassCollectionLoader::fixNamespaceDeclarations($source));
public function getFixNamespaceDeclarationsData()
{
return array(
array("namespace;\nclass Foo {}\n", "namespace\n{\nclass Foo {}\n}\n"),
array("namespace Foo;\nclass Foo {}\n", "namespace Foo\n{\nclass Foo {}\n}\n"),
array("namespace Bar ;\nclass Foo {}\n", "namespace Bar\n{\nclass Foo {}\n}\n"),
array("namespace Foo\Bar;\nclass Foo {}\n", "namespace Foo\Bar\n{\nclass Foo {}\n}\n"),
array("namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n", "namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n"),
array("namespace\n{\nclass Foo {}\n}\n", "namespace\n{\nclass Foo {}\n}\n"),
);
}
/**

View File

@@ -0,0 +1,52 @@
<?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\Tests;
use Symfony\Component\ClassLoader\ClassLoader;
use Symfony\Component\ClassLoader\DebugClassLoader;
class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase
{
private $loader;
protected function setUp()
{
$this->loader = new ClassLoader();
spl_autoload_register(array($this->loader, 'loadClass'));
}
protected function tearDown()
{
spl_autoload_unregister(array($this->loader, 'loadClass'));
}
public function testIdempotence()
{
DebugClassLoader::enable();
DebugClassLoader::enable();
$functions = spl_autoload_functions();
foreach ($functions as $function) {
if (is_array($function) && $function[0] instanceof DebugClassLoader) {
$reflClass = new \ReflectionClass($function[0]);
$reflProp = $reflClass->getProperty('classFinder');
$reflProp->setAccessible(true);
$this->assertNotInstanceOf('Symfony\Component\ClassLoader\DebugClassLoader', $reflProp->getValue($function[0]));
return;
}
}
throw new \Exception('DebugClassLoader did not register');
}
}

View File

@@ -26,10 +26,5 @@
"psr-0": { "Symfony\\Component\\ClassLoader": "" }
},
"target-dir": "Symfony/Component/ClassLoader",
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
}
"minimum-stability": "dev"
}