Skip to content

Commit fc3c572

Browse files
[DependencyInjection] Deprecate ContainerAwareInterface, ContainerAwareTrait and ContainerAwareLoader
1 parent 355b375 commit fc3c572

File tree

26 files changed

+167
-80
lines changed

26 files changed

+167
-80
lines changed

.github/expected-missing-return-types.diff

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,42 @@ git checkout src/Symfony/Contracts/Service/ResetInterface.php
88
git checkout composer.json src/
99

1010
diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
11-
index ada5fcbd49..51af652f08 100644
11+
index 8b57ff111c..92febe31e8 100644
1212
--- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
1313
+++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
14-
@@ -51,5 +51,5 @@ class DoctrineDataCollector extends DataCollector
15-
* @return void
14+
@@ -57,5 +57,5 @@ class DoctrineDataCollector extends DataCollector
15+
* @deprecated since Symfony 6.4, use a DebugDataHolder instead.
1616
*/
1717
- public function addLogger(string $name, DebugStack $logger)
1818
+ public function addLogger(string $name, DebugStack $logger): void
1919
{
20-
$this->loggers[$name] = $logger;
21-
@@ -59,5 +59,5 @@ class DoctrineDataCollector extends DataCollector
20+
trigger_deprecation('symfony/doctrine-bridge', '6.4', '"%s()" is deprecated. Pass an instance of "%s" to the constructor instead.', __METHOD__, DebugDataHolder::class);
21+
@@ -67,5 +67,5 @@ class DoctrineDataCollector extends DataCollector
2222
* @return void
2323
*/
2424
- public function collect(Request $request, Response $response, \Throwable $exception = null)
2525
+ public function collect(Request $request, Response $response, \Throwable $exception = null): void
2626
{
2727
$this->data = [
28-
@@ -90,5 +90,5 @@ class DoctrineDataCollector extends DataCollector
28+
@@ -98,5 +98,5 @@ class DoctrineDataCollector extends DataCollector
2929
* @return void
3030
*/
3131
- public function reset()
3232
+ public function reset(): void
3333
{
3434
$this->data = [];
35-
@@ -119,5 +119,5 @@ class DoctrineDataCollector extends DataCollector
35+
@@ -127,5 +127,5 @@ class DoctrineDataCollector extends DataCollector
3636
* @return int
3737
*/
3838
- public function getQueryCount()
3939
+ public function getQueryCount(): int
4040
{
4141
return array_sum(array_map('count', $this->data['queries']));
4242
diff --git a/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php b/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php
43-
index 4fa5057fe2..9e111adac5 100644
43+
index 448da935d9..06c97eb70c 100644
4444
--- a/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php
4545
+++ b/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php
46-
@@ -36,5 +36,5 @@ class ContainerAwareLoader extends Loader
46+
@@ -40,5 +40,5 @@ class ContainerAwareLoader extends Loader
4747
* @return void
4848
*/
4949
- public function addFixture(FixtureInterface $fixture)
@@ -202,10 +202,10 @@ index c096b558db..8d584900a9 100644
202202
{
203203
parent::configureOptions($resolver);
204204
diff --git a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
205-
index b2369e95d6..c33484608e 100644
205+
index d1a70f79d2..e052053918 100644
206206
--- a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
207207
+++ b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
208-
@@ -52,5 +52,5 @@ class DbalLogger implements SQLLogger
208+
@@ -56,5 +56,5 @@ class DbalLogger implements SQLLogger
209209
* @return void
210210
*/
211211
- protected function log(string $message, array $params)
@@ -502,7 +502,7 @@ index eadeafba55..4f1ca3bfef 100644
502502
{
503503
$configuration = new Configuration();
504504
diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php
505-
index cdbb90a3a9..b137a12012 100644
505+
index 5083538709..82093403f1 100644
506506
--- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php
507507
+++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php
508508
@@ -56,5 +56,5 @@ class Application extends BaseApplication
@@ -512,7 +512,7 @@ index cdbb90a3a9..b137a12012 100644
512512
+ public function reset(): void
513513
{
514514
if ($this->kernel->getContainer()->has('services_resetter')) {
515-
@@ -144,5 +144,5 @@ class Application extends BaseApplication
515+
@@ -145,5 +145,5 @@ class Application extends BaseApplication
516516
* @return void
517517
*/
518518
- protected function registerCommands()
@@ -4127,20 +4127,20 @@ index 3ea2228b94..f1d7078383 100644
41274127
{
41284128
return require $file;
41294129
diff --git a/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php b/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php
4130-
index 084a321ab5..09fb37f3aa 100644
4130+
index 9b3709c965..97b54712c9 100644
41314131
--- a/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php
41324132
+++ b/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php
4133-
@@ -24,4 +24,4 @@ interface ContainerAwareInterface
4133+
@@ -26,4 +26,4 @@ interface ContainerAwareInterface
41344134
* @return void
41354135
*/
41364136
- public function setContainer(?ContainerInterface $container);
41374137
+ public function setContainer(?ContainerInterface $container): void;
41384138
}
41394139
diff --git a/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php b/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
4140-
index ac67b468c5..bc1e395810 100644
4140+
index 4174fec8d0..f6a7b2da12 100644
41414141
--- a/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
41424142
+++ b/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
4143-
@@ -27,5 +27,5 @@ trait ContainerAwareTrait
4143+
@@ -31,5 +31,5 @@ trait ContainerAwareTrait
41444144
* @return void
41454145
*/
41464146
- public function setContainer(ContainerInterface $container = null)
@@ -4698,7 +4698,7 @@ index f610b014a0..9458751c28 100644
46984698
+ abstract protected function setNode(\DOMElement $node): void;
46994699
}
47004700
diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php
4701-
index 59eec3068c..b750e80938 100644
4701+
index 274aeee5fc..ccf37dae8b 100644
47024702
--- a/src/Symfony/Component/DomCrawler/Crawler.php
47034703
+++ b/src/Symfony/Component/DomCrawler/Crawler.php
47044704
@@ -96,5 +96,5 @@ class Crawler implements \Countable, \IteratorAggregate
@@ -8236,62 +8236,68 @@ index ed2189e4e7..28e90cdcf9 100644
82368236

82378237
public function getMetadataBag(): MetadataBag;
82388238
diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
8239-
index 2ddf55f2cb..52049a92b4 100644
8239+
index af21469b1c..7b024368c5 100644
82408240
--- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
82418241
+++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
8242-
@@ -35,5 +35,5 @@ abstract class Bundle implements BundleInterface
8242+
@@ -38,5 +38,5 @@ abstract class Bundle implements BundleInterface
82438243
* @return void
82448244
*/
82458245
- public function boot()
82468246
+ public function boot(): void
82478247
{
82488248
}
8249-
@@ -42,5 +42,5 @@ abstract class Bundle implements BundleInterface
8249+
@@ -45,5 +45,5 @@ abstract class Bundle implements BundleInterface
82508250
* @return void
82518251
*/
82528252
- public function shutdown()
82538253
+ public function shutdown(): void
82548254
{
82558255
}
8256-
@@ -52,5 +52,5 @@ abstract class Bundle implements BundleInterface
8256+
@@ -55,5 +55,5 @@ abstract class Bundle implements BundleInterface
82578257
* @return void
82588258
*/
82598259
- public function build(ContainerBuilder $container)
82608260
+ public function build(ContainerBuilder $container): void
82618261
{
82628262
}
8263-
@@ -122,5 +122,5 @@ abstract class Bundle implements BundleInterface
8263+
@@ -125,5 +125,5 @@ abstract class Bundle implements BundleInterface
82648264
* @return void
82658265
*/
82668266
- public function registerCommands(Application $application)
82678267
+ public function registerCommands(Application $application): void
82688268
{
82698269
}
82708270
diff --git a/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php b/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
8271-
index 02cb9641db..abe408eb24 100644
8271+
index fe200629f4..692c41ec53 100644
82728272
--- a/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
82738273
+++ b/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
8274-
@@ -28,5 +28,5 @@ interface BundleInterface extends ContainerAwareInterface
8274+
@@ -29,5 +29,5 @@ interface BundleInterface extends ContainerAwareInterface
82758275
* @return void
82768276
*/
82778277
- public function boot();
82788278
+ public function boot(): void;
82798279

82808280
/**
8281-
@@ -35,5 +35,5 @@ interface BundleInterface extends ContainerAwareInterface
8281+
@@ -36,5 +36,5 @@ interface BundleInterface extends ContainerAwareInterface
82828282
* @return void
82838283
*/
82848284
- public function shutdown();
82858285
+ public function shutdown(): void;
82868286

82878287
/**
8288-
@@ -44,5 +44,5 @@ interface BundleInterface extends ContainerAwareInterface
8288+
@@ -45,5 +45,5 @@ interface BundleInterface extends ContainerAwareInterface
82898289
* @return void
82908290
*/
82918291
- public function build(ContainerBuilder $container);
82928292
+ public function build(ContainerBuilder $container): void;
82938293

82948294
/**
8295+
@@ -72,4 +72,4 @@ interface BundleInterface extends ContainerAwareInterface
8296+
* @return void
8297+
*/
8298+
- public function setContainer(?ContainerInterface $container);
8299+
+ public function setContainer(?ContainerInterface $container): void;
8300+
}
82958301
diff --git a/src/Symfony/Component/HttpKernel/CacheClearer/CacheClearerInterface.php b/src/Symfony/Component/HttpKernel/CacheClearer/CacheClearerInterface.php
82968302
index 5ca4265624..1cb3611f8d 100644
82978303
--- a/src/Symfony/Component/HttpKernel/CacheClearer/CacheClearerInterface.php
@@ -8964,7 +8970,7 @@ index 0f3630e7fe..ddf77b8a19 100644
89648970
{
89658971
return <<<'EOF'
89668972
diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php
8967-
index 9d4c5f22b3..4030ab8b12 100644
8973+
index c2d67c0f17..5c4841305b 100644
89688974
--- a/src/Symfony/Component/HttpKernel/Kernel.php
89698975
+++ b/src/Symfony/Component/HttpKernel/Kernel.php
89708976
@@ -107,5 +107,5 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
@@ -10911,7 +10917,7 @@ index bde72c0eb0..3d6813e1d4 100644
1091110917
{
1091210918
if (!\is_array($config)) {
1091310919
diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php
10914-
index e92a5ea3d7..4a0af31349 100644
10920+
index 0e740bdf6c..21b68e3600 100644
1091510921
--- a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php
1091610922
+++ b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php
1091710923
@@ -54,5 +54,5 @@ EOF;

UPGRADE-6.4.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
UPGRADE FROM 6.3 to 6.4
22
=======================
33

4+
DependencyInjection
5+
-------------------
6+
7+
* Deprecate `ContainerAwareInterface` and `ContainerAwareTrait`, use dependency injection instead
8+
49
DoctrineBridge
510
--------------
611

712
* Deprecate `DbalLogger`, use a middleware instead
813
* Deprecate not constructing `DoctrineDataCollector` with an instance of `DebugDataHolder`
914
* Deprecate `DoctrineDataCollector::addLogger()`, use a `DebugDataHolder` instead
15+
* Deprecate `ContainerAwareLoader`, use dependency injection in your fixtures instead
1016

1117
HttpFoundation
1218
--------------

src/Symfony/Bridge/Doctrine/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Deprecate `DbalLogger`, use a middleware instead
88
* Deprecate not constructing `DoctrineDataCollector` with an instance of `DebugDataHolder`
99
* Deprecate `DoctrineDataCollector::addLogger()`, use a `DebugDataHolder` instead
10+
* Deprecate `ContainerAwareLoader`, use dependency injection in your fixtures instead
1011

1112
6.3
1213
---

src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
1717
use Symfony\Component\DependencyInjection\ContainerInterface;
1818

19+
trigger_deprecation('symfony/dependency-injection', '6.4', '"%s" is deprecated, use dependency injection in your fixtures instead.', ContainerAwareLoader::class);
20+
1921
/**
2022
* Doctrine data fixtures loader that injects the service container into
2123
* fixture objects that implement ContainerAwareInterface.
2224
*
2325
* Note: Use of this class requires the Doctrine data fixtures extension, which
2426
* is a suggested dependency for Symfony.
27+
*
28+
* @deprecated since Symfony 6.4, use dependency injection in your fixtures instead
2529
*/
2630
class ContainerAwareLoader extends Loader
2731
{

src/Symfony/Bridge/Doctrine/Tests/DataFixtures/ContainerAwareLoaderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Symfony\Bridge\Doctrine\Tests\Fixtures\ContainerAwareFixture;
1717
use Symfony\Component\DependencyInjection\ContainerInterface;
1818

19+
/**
20+
* @group legacy
21+
*/
1922
class ContainerAwareLoaderTest extends TestCase
2023
{
2124
public function testShouldSetContainerOnContainerAwareFixture()

src/Symfony/Bridge/Doctrine/Tests/Fixtures/ContainerAwareFixture.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
1717
use Symfony\Component\DependencyInjection\ContainerInterface;
1818

19+
/**
20+
* @deprecated since Symfony 6.4, to be removed in 7.0
21+
*/
1922
class ContainerAwareFixture implements FixtureInterface, ContainerAwareInterface
2023
{
2124
public ?ContainerInterface $container = null;

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function get(string $name): Command
115115
$command = parent::get($name);
116116

117117
if ($command instanceof ContainerAwareInterface) {
118+
trigger_deprecation('symfony/dependency-injection', '6.4', 'Relying on "%s" to get the container in "%s" is deprecated, register the command as a service and use dependency injection instead.', ContainerAwareInterface::class, get_debug_type($command));
118119
$command->setContainer($this->kernel->getContainer());
119120
}
120121

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function instantiateController(string $class): object
2626
$controller = parent::instantiateController($class);
2727

2828
if ($controller instanceof ContainerAwareInterface) {
29+
trigger_deprecation('symfony/dependency-injection', '6.4', 'Relying on "%s" to get the container in "%s" is deprecated, register the controller as a service and use dependency injection instead.', ContainerAwareInterface::class, get_debug_type($controller));
2930
$controller->setContainer($this->container);
3031
}
3132
if ($controller instanceof AbstractController) {

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

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

1414
use Psr\Container\ContainerInterface as Psr11ContainerInterface;
1515
use Psr\Log\LoggerInterface;
16+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1617
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1718
use Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver;
1819
use Symfony\Component\DependencyInjection\Container;
@@ -23,31 +24,44 @@
2324

2425
class ControllerResolverTest extends ContainerControllerResolverTest
2526
{
27+
use ExpectDeprecationTrait;
28+
29+
/**
30+
* @group legacy
31+
*/
2632
public function testGetControllerOnContainerAware()
2733
{
2834
$resolver = $this->createControllerResolver();
2935
$request = Request::create('/');
3036
$request->attributes->set('_controller', 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController::testAction');
3137

38+
$this->expectDeprecation('Since symfony/dependency-injection 6.4: Relying on "Symfony\Component\DependencyInjection\ContainerAwareInterface" to get the container in "Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController" is deprecated, register the controller as a service and use dependency injection instead.');
3239
$controller = $resolver->getController($request);
3340

3441
$this->assertInstanceOf(ContainerAwareController::class, $controller[0]);
3542
$this->assertInstanceOf(ContainerInterface::class, $controller[0]->getContainer());
3643
$this->assertSame('testAction', $controller[1]);
3744
}
3845

46+
/**
47+
* @group legacy
48+
*/
3949
public function testGetControllerOnContainerAwareInvokable()
4050
{
4151
$resolver = $this->createControllerResolver();
4252
$request = Request::create('/');
4353
$request->attributes->set('_controller', 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController');
4454

55+
$this->expectDeprecation('Since symfony/dependency-injection 6.4: Relying on "Symfony\Component\DependencyInjection\ContainerAwareInterface" to get the container in "Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController" is deprecated, register the controller as a service and use dependency injection instead.');
4556
$controller = $resolver->getController($request);
4657

4758
$this->assertInstanceOf(ContainerAwareController::class, $controller);
4859
$this->assertInstanceOf(ContainerInterface::class, $controller->getContainer());
4960
}
5061

62+
/**
63+
* @group legacy
64+
*/
5165
public function testContainerAwareControllerGetsContainerWhenNotSet()
5266
{
5367
class_exists(AbstractControllerTest::class);
@@ -62,6 +76,7 @@ class_exists(AbstractControllerTest::class);
6276
$request = Request::create('/');
6377
$request->attributes->set('_controller', TestAbstractController::class.'::testAction');
6478

79+
$this->expectDeprecation('Since symfony/dependency-injection 6.4: Relying on "Symfony\Component\DependencyInjection\ContainerAwareInterface" to get the container in "Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController" is deprecated, register the controller as a service and use dependency injection instead.');
6580
$this->assertSame([$controller, 'testAction'], $resolver->getController($request));
6681
$this->assertSame($container, $controller->getContainer());
6782
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@
1111

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

14-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
1614
use Symfony\Component\HttpFoundation\Request;
1715
use Symfony\Component\HttpFoundation\Response;
1816
use Symfony\Component\HttpKernel\Controller\ControllerReference;
1917
use Symfony\Component\HttpKernel\Fragment\FragmentUriGeneratorInterface;
2018
use Twig\Environment;
2119

22-
class FragmentController implements ContainerAwareInterface
20+
class FragmentController
2321
{
24-
use ContainerAwareTrait;
25-
2622
public function indexAction(Environment $twig)
2723
{
2824
return new Response($twig->render('fragment.html.twig', ['bar' => new Bar()]));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy