8000 feature #35879 [DependencyInjection] Deprecate ContainerInterface ali… · symfony/symfony@2fc5f13 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2fc5f13

Browse files
feature #35879 [DependencyInjection] Deprecate ContainerInterface aliases (fancyweb)
This PR was merged into the 5.1-dev branch. Discussion ---------- [DependencyInjection] Deprecate ContainerInterface aliases | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT | Doc PR | - Defining those aliases makes it harder to detect problems when you use `!tagged_locator` or any service locator with autowiring since the global service container is always injected. Moreover, should we encourage passing the global service container easily? Shouldn't it be more "explicit"? I think that by default, those aliases should not exist. However, that means we will have to reintroduce code to hook the global service container in our own code base since some part rely on it (~~eg: FWB AbstractController::setContainer~~). WDYT? 🤷‍♂ Commits ------- 6162ca8 [DependencyInjection] Deprecate ContainerInterface aliases
2 parents 0a8d638 + 6162ca8 commit 2fc5f13

24 files changed

+171
-30
lines changed

UPGRADE-5.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ DependencyInjection
1212
* The signature of method `Definition::setDeprecated()` has been updated to `Definition::setDeprecation(string $package, string $version, string $message)`.
1313
* The signature of method `Alias::setDeprecated()` has been updated to `Alias::setDeprecation(string $package, string $version, string $message)`.
1414
* The signature of method `DeprecateTrait::deprecate()` has been updated to `DeprecateTrait::deprecation(string $package, string $version, string $message)`.
15+
* Deprecated the `Psr\Container\ContainerInterface` and `Symfony\Component\DependencyInjection\ContainerInterface` aliases of the `service_container` service,
16+
configure them explicitly instead.
1517

1618
Dotenv
1719
------

UPGRADE-6.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ DependencyInjection
1212
* The signature of method `Definition::setDeprecated()` has been updated to `Definition::setDeprecation(string $package, string $version, string $message)`.
1313
* The signature of method `Alias::setDeprecated()` has been updated to `Alias::setDeprecation(string $package, string $version, string $message)`.
1414
* The signature of method `DeprecateTrait::deprecate()` has been updated to `DeprecateTrait::deprecation(string $package, string $version, string $message)`.
15+
* Removed the `Psr\Container\ContainerInterface` and `Symfony\Component\DependencyInjection\ContainerInterface` aliases of the `service_container` service,
16+
configure them explicitly instead.
1517

1618
Dotenv
1719
------

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/AddSessionDomainConstraintPassTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Psr\Container\ContainerInterface;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
1617
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSessionDomainConstraintPass;
1718
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
19+
use Symfony\Component\DependencyInjection\Alias;
20+
use Symfony\Component\DependencyInjection\Container;
1821
use Symfony\Component\DependencyInjection\ContainerBuilder;
22+
use Symfony\Component\DependencyInjection\Definition;
1923
use Symfony\Component\HttpFoundation\Request;
2024

2125
class AddSessionDomainConstraintPassTest extends TestCase
@@ -148,6 +152,9 @@ private function createContainer($sessionStorageOptions)
148152
$pass = new AddSessionDomainConstraintPass();
149153
$pass->process($container);
150154

155+
$container->setDefinition('.service_subscriber.fallback_container', new Definition(Container::class));
156+
$container->setAlias(ContainerInterface::class, new Alias('.service_subscriber.fallback_container', false));
157+
151158
return $container;
152159
}
153160
}

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ CHANGELOG
1010
* updated the signature of method `Definition::setDeprecated()` to `Definition::setDeprecation(string $package, string $version, string $message)`
1111
* updated the signature of method `Alias::setDeprecated()` to `Alias::setDeprecation(string $package, string $version, string $message)`
1212
* updated the signature of method `DeprecateTrait::deprecate()` to `DeprecateTrait::deprecation(string $package, string $version, string $message)`
13+
* deprecated the `Psr\Container\ContainerInterface` and `Symfony\Component\DependencyInjection\ContainerInterface` aliases of the `service_container` service,
14+
configure them explicitly instead
1315

1416
5.0.0
1517
-----

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ public function __construct(ParameterBagInterface $parameterBag = null)
147147

148148
$this->trackResources = interface_exists('Symfony\Component\Config\Resource\ResourceInterface');
149149
$this->setDefinition('service_container', (new Definition(ContainerInterface::class))->setSynthetic(true)->setPublic(true));
150-
$this->setAlias(PsrContainerInterface::class, new Alias('service_container', false));
151-
$this->setAlias(ContainerInterface::class, new Alias('service_container', false));
150+
$this->setAlias(PsrContainerInterface::class, new Alias('service_container', false))->setDeprecated('symfony/dependency-injection', '5.1', $deprecationMessage = 'The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.');
151+
$this->setAlias(ContainerInterface::class, new Alias('service_container', false))->setDeprecated('symfony/dependency-injection', '5.1', $deprecationMessage);
152152
}
153153

154154
/**

src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ public function testDumpAnonymousServices()
8888
</service>
8989
</argument>
9090
</service>
91-
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false"/>
92-
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false"/>
91+
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false">
92+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
93+
</service>
94+
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false">
95+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
96+
</service>
9397
</services>
9498
</container>
9599
', $dumper->dump());
@@ -107,8 +111,12 @@ public function testDumpEntities()
107111
<tag name=\"foo&quot;bar\bar\" foo=\"foo&quot;barřž€\"/>
108112
<argument>foo&lt;&gt;&amp;bar</argument>
109113
</service>
110-
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
111-
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
114+
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\">
115+
<deprecated package=\"symfony/dependency-injection\" version=\"5.1\">The \"%alias_id%\" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
116+
</service>
117+
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\">
118+
<deprecated package=\"symfony/dependency-injection\" version=\"5.1\">The \"%alias_id%\" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
119+
</service>
112120
</services>
113121
</container>
114122
", $dumper->dump());
@@ -133,8 +141,12 @@ public function provideDecoratedServicesData()
133141
<services>
134142
<service id=\"service_container\" class=\"Symfony\Component\DependencyInjection\ContainerInterface\" public=\"true\" synthetic=\"true\"/>
135143
<service id=\"foo\" class=\"FooClass\Foo\" public=\"true\" decorates=\"bar\" decoration-inner-name=\"bar.woozy\"/>
136-
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
137-
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
144+
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\">
145+
<deprecated package=\"symfony/dependency-injection\" version=\"5.1\">The \"%alias_id%\" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
146+
</service>
147+
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\">
148+
<deprecated package=\"symfony/dependency-injection\" version=\"5.1\">The \"%alias_id%\" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
149+
</service>
138150
</services>
139151
</container>
140152
", include $fixturesPath.'/containers/container15.php'],
@@ -143,8 +155,12 @@ public function provideDecoratedServicesData()
143155
<services>
144156
<service id=\"service_container\" class=\"Symfony\Component\DependencyInjection\ContainerInterface\" public=\"true\" synthetic=\"true\"/>
145157
<service id=\"foo\" class=\"FooClass\Foo\" public=\"true\" decorates=\"bar\"/>
146-
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
147-
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
158+
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\">
159+
<deprecated package=\"symfony/dependency-injection\" version=\"5.1\">The \"%alias_id%\" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
160+
</service>
161+
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\">
162+
<deprecated package=\"symfony/dependency-injection\" version=\"5.1\">The \"%alias_id%\" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
163+
</service>
148164
</services>
149165
</container>
150166
", include $fixturesPath.'/containers/container16.php'],
@@ -153,8 +169,12 @@ public function provideDecoratedServicesData()
153169
<services>
154170
<service id=\"service_container\" class=\"Symfony\Component\DependencyInjection\ContainerInterface\" public=\"true\" synthetic=\"true\"/>
155171
<service id=\"decorator\" decorates=\"decorated\" decoration-on-invalid=\"null\" decoration-inner-name=\"decorated.inner\" decoration-priority=\"1\"/>
156-
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
157-
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\"/>
172+
<service id=\"Psr\Container\ContainerInterface\" alias=\"service_container\" public=\"false\">
173+
<deprecated package=\"symfony/dependency-injection\" version=\"5.1\">The \"%alias_id%\" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
174+
</service>
175+
<service id=\"Symfony\Component\DependencyInjection\ContainerInterface\" alias=\"service_container\" public=\"false\">
176+
<deprecated package=\"symfony/dependency-injection\" version=\"5.1\">The \"%alias_id%\" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
177+
</service>
158178
</services>
159179
</container>
160180
", include $fixturesPath.'/containers/container34.php'],

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services1.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
33
<services>
44
<service class="Symfony\Component\DependencyInjection\ContainerInterface" id="service_container" public="true" synthetic="true"/>
5-
<service alias="service_container" id="Psr\Container\ContainerInterface" public="false"/>
6-
<service alias="service_container" id="Symfony\Component\DependencyInjection\ContainerInterface" public="false"/>
5+
<service alias="service_container" id="Psr\Container\ContainerInterface" public="false">
6+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
7+
</service>
8+
<service alias="service_container" id="Symfony\Component\DependencyInjection\ContainerInterface" public="false">
9+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
10+
</service>
711
</services>
812
</container>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services21.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
</service>
1919
</configurator>
2020
</service>
21-
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false"/>
22-
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false"/>
21+
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false">
22+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
23+
</service>
24+
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false">
25+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
26+
</service>
2327
</services>
2428
</container>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services24.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
<services>
44
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
55
<service id="foo" class="Foo" public="true" autowire="true"/>
6-
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false"/>
7-
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false"/>
6+
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false">
7+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
8+
</service>
9+
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false">
10+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
11+
</service>
812
</services>
913
</container>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services8.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
</parameters>
3535
<services>
3636
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
37-
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false"/>
38-
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false"/>
37+
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false">
38+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
39+
</service>
40+
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false">
41+
<deprecated package="symfony/dependency-injection" version="5.1">The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.</deprecated>
42+
</service>
3943
</services>
4044
</container>

0 commit comments

Comments
 (0)
0