8000 [ClassLoader] Deprecated the component · symfony/symfony@28e815a · GitHub
[go: up one dir, main page]

Skip to content

Commit 28e815a

Browse files
[ClassLoader] Deprecated the component
1 parent 5921530 commit 28e815a

File tree

14 files changed

+44
-30
lines changed

14 files changed

+44
-30
lines changed

UPGRADE-3.3.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ UPGRADE FROM 3.2 to 3.3
44
ClassLoader
55
-----------
66

7-
* The ApcClassLoader, WinCacheClassLoader and XcacheClassLoader classes have been deprecated
8-
in favor of the `--apcu-autoloader` option introduced in composer 1.3
7+
* The component is deprecated and will be removed in 4.0. Use composer instead.
98

109
DependencyInjection
1110
-------------------

UPGRADE-4.0.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ UPGRADE FROM 3.x to 4.0
44
ClassLoader
55
-----------
66

7-
* The ApcClassLoader, WinCacheClassLoader and XcacheClassLoader classes have been removed
8-
in favor of the `--apcu-autoloader` option introduced in composer 1.3
7+
* The component has been removed. Use composer instead.
98

109
Console
1110
-------

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
1313

14+
use Composer\Autoload\ClassLoader;
1415
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1516
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
16-
use Symfony\Component\ClassLoader\ClassLoader;
1717

1818
class ControllerNameParserTest extends TestCase
1919
{
@@ -22,17 +22,14 @@ class ControllerNameParserTest extends TestCase
2222
protected function setUp()
2323
{
2424
$this->loader = new ClassLoader();
25-
$this->loader->addPrefixes(array(
26-
'TestBundle' => __DIR__.'/../Fixtures',
27-
'TestApplication' => __DIR__.'/../Fixtures',
28-
));
25+
$this->loader->add('TestBundle', __DIR__.'/../Fixtures');
26+
$this->loader->add('TestApplication', __DIR__.'/../Fixtures');
2927
$this->loader->register();
3028
}
3129

3230
protected function tearDown()
3331
{
34-
spl_autoload_unregister(array($this->loader, 'loadClass'));
35-
32+
$this->loader->unregister();
3633
$this->loader = null;
3734
}
3835

src/Symfony/Component/ClassLoader/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ CHANGELOG
44
3.3.0
55
-----
66

7-
* The ApcClassLoader, WinCacheClassLoader and XcacheClassLoader classes have been deprecated
8-
in favor of the `--apcu-autoloader` option introduced in composer 1.3
7+
* deprecated the component: use composer instead
98

109
3.0.0
1110
-----

src/Symfony/Component/ClassLoader/ClassLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\ClassLoader;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\ClassLoader class is deprecated since version 3.3 and will be removed in 4.0. Use composer instead.', E_USER_DEPRECATED);
15+
1416
/**
1517
* ClassLoader implements an PSR-0 class loader.
1618
*

src/Symfony/Component/ClassLoader/ClassMapGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\ClassLoader;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\ClassMapGenerator class is deprecated since version 3.3 and will be removed in 4.0. Use composer instead.', E_USER_DEPRECATED);
15+
1416
/**
1517
* ClassMapGenerator.
1618
*

src/Symfony/Component/ClassLoader/MapClassLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\ClassLoader;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\MapClassLoader class is deprecated since version 3.3 and will be removed in 4.0. Use composer instead.', E_USER_DEPRECATED);
15+
1416
/**
1517
* A class loader that uses a mapping file to look up paths.
1618
*

src/Symfony/Component/ClassLoader/Psr4ClassLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\ClassLoader;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\Psr4ClassLoader class is deprecated since version 3.3 and will be removed in 4.0. Use composer instead.', E_USER_DEPRECATED);
15+
1416
/**
1517
* A PSR-4 compatible class loader.
1618
*

src/Symfony/Component/ClassLoader/Tests/ClassLoaderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Symfony\Component\ClassLoader\ClassLoader;
1515

16+
/**
17+
* @group legacy
18+
*/
1619
class ClassLoaderTest extends \PHPUnit_Framework_TestCase
1720
{
1821
public function testGetPrefixes()

src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Symfony\Component\ClassLoader\ClassMapGenerator;
1515

16+
/**
17+
* @group legacy
18+
*/
1619
class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
1720
{
1821
/**

src/Symfony/Component/ClassLoader/Tests/Psr4ClassLoaderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Symfony\Component\ClassLoader\Psr4ClassLoader;
1515

16+
/**
17+
* @group legacy
18+
*/
1619
class Psr4ClassLoaderTest extends \PHPUnit_Framework_TestCase
1720
{
1821
/**

src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Debug\Tests\FatalErrorHandler;
1313

1414
use Symfony\Component\Debug\Exception\FatalErrorException;
15-
use Symfony\Component\ClassLoader\ClassLoader as SymfonyClassLoader;
1615
use Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler;
1716
use Symfony\Component\Debug\DebugClassLoader;
1817
use Composer\Autoload\ClassLoader as ComposerClassLoader;
@@ -69,12 +68,10 @@ public function testHandleClassNotFound($error, $tran F42D slatedMessage, $autoloader
6968

7069
public function provideClassNotFoundData()
7170
{
72-
$prefixes = array('Symfony\Component\Debug\Exception\\' => realpath(__DIR__.'/../../Exception'));
71+
$autoloader = new ComposerClassLoader();
72+
$autoloader->add('Symfony\Component\Debug\Exception\\', realpath(__DIR__.'/../../Exception'));
7373

74-
$symfonyAutoloader = new SymfonyClassLoader();
75-
$symfonyAutoloader->addPrefixes($prefixes);
76-
77-
$debugClassLoader = new DebugClassLoader(array($symfonyAutoloader, 'loadClass'));
74+
$debugClassLoader = new DebugClassLoader(array($autoloader, 'loadClass'));
7875

7976
return array(
8077
array(
@@ -130,7 +127,7 @@ public function provideClassNotFoundData()
130127
'message' => 'Class \'Foo\\Bar\\UndefinedFunctionException\' not found',
131128
),
132129
"Attempted to load class \"UndefinedFunctionException\" from namespace \"Foo\Bar\".\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?",
133-
array($symfonyAutoloader, 'loadClass'),
130+
array($autoloader, 'loadClass'),
134131
),
135132
array(
136133
array(

src/Symfony/Component/Debug/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
2424
},
2525
"require-dev": {
26-
"symfony/class-loader": "~2.8|~3.0",
2726
"symfony/http-kernel": "~2.8|~3.0"
2827
},
2928
"autoload": {

src/Symfony/Component/HttpKernel/Client.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,29 @@ protected function getScript($request)
9696
{
9797
$kernel = str_replace("'", "\\'", serialize($this->kernel));
9898
$request = str_replace("'", "\\'", serialize($request));
99-
100-
$r = new \ReflectionClass('\\Symfony\\Component\\ClassLoader\\ClassLoader');
101-
$requirePath = str_replace("'", "\\'", $r->getFileName());
102-
$symfonyPath = str_replace("'", "\\'", dirname(dirname(dirname(__DIR__))));
10399
$errorReporting = error_reporting();
104100

101+
$requires = '';
102+
foreach (get_declared_classes() as $class) {
103+
if (0 === strpos($class, 'ComposerAutoloaderInit')) {
104+
$r = new \ReflectionClass($class);
105+
$file = dirname(dirname($r->getFileName())).'/autoload.php';
106+
if (file_exists($file)) {
107+
$requires .= "require_once '".str_replace("'", "\\'", $file)."';\n";
108+
}
109+
}
110+
}
111+
112+
if (!$requires) {
113+
throw new \RuntimeException('Composer autoloader not found.');
114+
}
115+
105116
$code = <<<EOF
106117
<?php
107118
108119
error_reporting($errorReporting);
109120
110-
require_once '$requirePath';
111-
112-
\$loader = new Symfony\Component\ClassLoader\ClassLoader();
113-
\$loader->addPrefix('Symfony', '$symfonyPath');
114-
\$loader->register();
121+
$requires
115122
116123
\$kernel = unserialize('$kernel');
117124
\$request = unserialize('$request');

0 commit comments

Comments
 (0)
0