Skip to content

Commit 80d4449

Browse files
committed
remove ability to access $this and the loader's internal state
1 parent 38dfd93 commit 80d4449

File tree

10 files changed

+11
-82
lines changed

10 files changed

+11
-82
lines changed

UPGRADE-8.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Cache
2727
Config
2828
------
2929

30+
* Remove support for accessing the internal scope of the loader in PHP config files, use only its public API instead
3031
* Add argument `$singular` to `NodeBuilder::arrayNode()`
3132
* Add argument `$info` to `ArrayNodeDefinition::canBeDisabled()` and `canBeEnabled()`
3233

@@ -95,6 +96,7 @@ Console
9596
DependencyInjection
9697
-------------------
9798

99+
* Remove support for using `$this` or the loader's internal scope from PHP config files; use the `$loader` variable instead
98100
* Remove `ExtensionInterface::getXsdValidationBasePath()` and `getNamespace()` without alternatives, the XML configuration format is no longer supported
99101
* Add argument `$throwOnAbstract` to `ContainerBuilder::findTaggedResourceIds()`
100102
* Registering a service without a class when its id is a non-existing FQCN throws an error
@@ -366,6 +368,7 @@ PropertyInfo
366368
Routing
367369
-------
368370

371+
* Remove support for accessing the internal scope of the loader in PHP config files, use only its public API instead
369372
* Providing a non-array `_query` parameter to `UrlGenerator` causes an `InvalidParameterException`
370373
* Remove the protected `AttributeClassLoader::$routeAnnotationClass` property and the `setRouteAnnotationClass()` method, use `AttributeClassLoader::setRouteAttributeClass()` instead
371374
* Remove class aliases in the `Annotation` namespace, use attributes instead

src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
8.0
55
---
66

7+
* Remove support for accessing the internal scope of the loader in PHP config files, use only its public API instead
78
* Add argument `$singular` to `NodeBuilder::arrayNode()`
89
* Add argument `$info` to `ArrayNodeDefinition::canBeDisabled()` and `canBeEnabled()`
910

src/Symfony/Component/Config/Definition/Loader/DefinitionFileLoader.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,7 @@ public function load(mixed $resource, ?string $type = null): mixed
4848
return include $file;
4949
}, null, null);
5050

51-
try {
52-
$callback = $load($path);
53-
} catch (\Error $e) {
54-
$load = \Closure::bind(static function ($file) use ($loader) {
55-
return include $file;
56-
}, null, ProtectedDefinitionFileLoader::class);
57-
58-
$callback = $load($path);
59-
60-
trigger_deprecation('symfony/config', '7.4', 'Accessing the internal scope of the loader in config files is deprecated, use only its public API instead in "%s" on line %d.', $e->getFile(), $e->getLine());
61-
}
51+
$callback = $load($path);
6252

6353
if (\is_object($callback) && \is_callable($callback)) {
6454
$this->callConfigurator($callback, new DefinitionConfigurator($this->treeBuilder, $this, $path, $resource), $path);

src/Symfony/Component/Config/Tests/Definition/Loader/DefinitionFileLoaderTest.php

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

1212
namespace Symfony\Component\Config\Tests\Definition\Loader;
1313

14-
use PHPUnit\Framework\Attributes\Group;
15-
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1614
use PHPUnit\Framework\TestCase;
1715
use Symfony\Component\Config\Definition\BaseNode;
1816
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -41,15 +39,4 @@ public function testLoad()
4139
$this->assertInstanceOf(BaseNode::class, $children['foo']);
4240
$this->assertSame('test.foo', $children['foo']->getPath(), '->load() loads a PHP file resource');
4341
}
44-
45-
#[IgnoreDeprecations]
46-
#[Group('legacy')]
47-
public function testTriggersDeprecationWhenAccessingLoaderInternalScope()
48-
{
49-
$loader = new DefinitionFileLoader(new TreeBuilder('test'), new FileLocator(__DIR__.'/../../Fixtures/Loader'));
50-
51-
$this->expectUserDeprecationMessageMatches('{^Since symfony/config 7.4: Accessing the internal scope of the loader in config files is deprecated, use only its public API instead in ".+" on line \d+\.$}');
52-
53-
$loader->load('legacy_internal_scope.php');
54-
}
5542
}

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
8.0
55
---
66

7+
* Remove support for using `$this` or the loader's internal scope from PHP config files; use the `$loader` variable instead
78
* Remove `ExtensionInterface::getXsdValidationBasePath()` and `getNamespace()` without alternatives, the XML configuration format is no longer supported
89
* Add argument `$throwOnAbstract` to `ContainerBuilder::findTaggedResourceIds()`
910
* Registering a service without a class when its id is a non-existing FQCN throws an error

src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,8 @@ class_exists(ContainerConfigurator::class);
7575
}, null, null);
7676

7777
try {
78-
try {
79-
if (1 === $result = $load($path, $this->env)) {
80-
$result = null;
81-
}
82-
} catch (\Error $e) {
83-
$load = \Closure::bind(function ($path, $env) use ($container, $loader, $resource, $type) {
84-
return include $path;
85-
}, $this, ProtectedPhpFileLoader::class);
86-
87-
if (1 === $result = $load($path, $this->env)) {
88-
$result = null;
89-
}
90-
91-
trigger_deprecation('symfony/dependency-injection', '8.1', 'Using `$this` or its internal scope in config files is deprecated, use the `$loader` variable instead in "%s" on line %d.', $e->getFile(), $e->getLine());
78+
if (1 === $result = $load($path, $this->env)) {
79+
$result = null;
9280
}
9381

9482
if (\is_object($result) && \is_callable($result)) {

src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
require_once __DIR__.'/../Fixtures/includes/fixture_app_services.php';
1616

1717
use PHPUnit\Framework\Attributes\DataProvider;
18-
use PHPUnit\Framework\Attributes\Group;
19-
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
2018
use PHPUnit\Framework\TestCase;
2119
use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
2220
use Symfony\Component\Config\FileLocator;
@@ -368,16 +366,4 @@ public function testReturnsGenerator()
368366
$loader->load('return_generator.php');
369367
$this->assertSame([['color' => 'red']], $container->getExtensionConfig('acme'));
370368
}
371-
372-
#[IgnoreDeprecations]
373-
#[Group('legacy')]
374-
public function testTriggersDeprecationWhenAccessingLoaderInternalScope()
375-
{
376-
$fixtures = realpath(__DIR__.'/../Fixtures');
377-
$loader = new PhpFileLoader(new ContainerBuilder(), new FileLocator($fixtures.'/config'));
378-
379-
$this->expectUserDeprecationMessageMatches('{^Since symfony/dependency-injection 8.1: Using \`\$this\` or its internal scope in config files is deprecated, use the \`\$loader\` variable instead in ".+" on line \d+\.$}');
380-
381-
$loader->load('legacy_internal_scope.php');
382-
}
383369
}

src/Symfony/Component/Routing/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
8.0
55
---
66

7+
* Remove support for accessing the internal scope of the loader in PHP config files, use only its public API instead
78
* Providing a non-array `_query` parameter to `UrlGenerator` causes an `InvalidParameterException`
89
* Remove the protected `AttributeClassLoader::$routeAnnotationClass` property and the `setRouteAnnotationClass()` method, use `AttributeClassLoader::setRouteAttributeClass()` instead
910
* Remove class aliases in the `Annotation` namespace, use attributes instead

src/Symfony/Component/Routing/Loader/PhpFileLoader.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,8 @@ public function load(mixed $file, ?string $type = null): RouteCollection
4545
return include $file;
4646
}, null, null);
4747

48-
try {
49-
if (1 === $result = $load($path)) {
50-
$result = null;
51-
}
52-
} catch (\Error $e) {
53-
$load = \Closure::bind(static function ($file) use ($loader) {
54-
return include $file;
55-
}, null, ProtectedPhpFileLoader::class);
56-
57-
if (1 === $result = $load($path)) {
58-
$result = null;
59-
}
60-
61-
trigger_deprecation('symfony/routing', '7.4', 'Accessing the internal scope of the loader in config files is deprecated, use only its public API instead in "%s" on line %d.', $e->getFile(), $e->getLine());
48+
if (1 === $result = $load($path)) {
49+
$result = null;
6250
}
6351

6452
if (\is_object($result) && \is_callable($result)) {

src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\Routing\Tests\Loader;
1313

1414
use PHPUnit\Framework\Attributes\DataProvider;
15-
use PHPUnit\Framework\Attributes\Group;
16-
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1715
use PHPUnit\Framework\TestCase;
1816
use Symfony\Component\Config\FileLocator;
1917
use Symfony\Component\Config\Loader\LoaderResolver;
@@ -260,20 +258,6 @@ public function testRoutingConfiguratorCanImportGlobPatterns()
260258
$this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
261259
}
262260

263-
#[IgnoreDeprecations]
264-
#[Group('legacy')]
265-
public function testTriggersDeprecationWhenAccessingLoaderInternalScope()
266-
{
267-
$locator = new FileLocator([__DIR__.'/../Fixtures']);
268-
$loader = new PhpFileLoader($locator);
269-
270-
$this->expectUserDeprecationMessageMatches('{^Since symfony/routing 7.4: Accessing the internal scope of the loader in config files is deprecated, use only its public API instead in ".+" on line \d+\.$}');
271-
272-
$routes = $loader->load('legacy_internal_scope.php');
273-
274-
$this->assertInstanceOf(RouteCollection::class, $routes);
275-
}
276-
277261
public function testRoutingI18nConfigurator()
278262
{
279263
$locator = new FileLocator([__DIR__.'/../Fixtures']);

0 commit comments

Comments
 (0)