Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Deprecate ContainerAwareInterface, ContainerAwareTrait and ContainerAwareLoader #50615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 35 additions & 29 deletions .github/expected-missing-return-types.diff
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@ git checkout src/Symfony/Contracts/Service/ResetInterface.php
git checkout composer.json src/

diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
index ada5fcbd49..51af652f08 100644
index 8b57ff111c..92febe31e8 100644
--- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
+++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
@@ -51,5 +51,5 @@ class DoctrineDataCollector extends DataCollector
* @return void
@@ -57,5 +57,5 @@ class DoctrineDataCollector extends DataCollector
* @deprecated since Symfony 6.4, use a DebugDataHolder instead.
*/
- public function addLogger(string $name, DebugStack $logger)
+ public function addLogger(string $name, DebugStack $logger): void
{
$this->loggers[$name] = $logger;
@@ -59,5 +59,5 @@ class DoctrineDataCollector extends DataCollector
trigger_deprecation('symfony/doctrine-bridge', '6.4', '"%s()" is deprecated. Pass an instance of "%s" to the constructor instead.', __METHOD__, DebugDataHolder::class);
@@ -67,5 +67,5 @@ class DoctrineDataCollector extends DataCollector
* @return void
*/
- public function collect(Request $request, Response $response, \Throwable $exception = null)
+ public function collect(Request $request, Response $response, \Throwable $exception = null): void
{
$this->data = [
@@ -90,5 +90,5 @@ class DoctrineDataCollector extends DataCollector
@@ -98,5 +98,5 @@ class DoctrineDataCollector extends DataCollector
* @return void
*/
- public function reset()
+ public function reset(): void
{
$this->data = [];
@@ -119,5 +119,5 @@ class DoctrineDataCollector extends DataCollector
@@ -127,5 +127,5 @@ class DoctrineDataCollector extends DataCollector
* @return int
*/
- public function getQueryCount()
+ public function getQueryCount(): int
{
return array_sum(array_map('count', $this->data['queries']));
diff --git a/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php b/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php
index 4fa5057fe2..9e111adac5 100644
index 448da935d9..06c97eb70c 100644
--- a/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php
+++ b/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php
@@ -36,5 +36,5 @@ class ContainerAwareLoader extends Loader
@@ -40,5 +40,5 @@ class ContainerAwareLoader extends Loader
* @return void
*/
- public function addFixture(FixtureInterface $fixture)
Expand Down Expand Up @@ -202,10 +202,10 @@ index c096b558db..8d584900a9 100644
{
parent::configureOptions($resolver);
diff --git a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
index b2369e95d6..c33484608e 100644
index d1a70f79d2..e052053918 100644
--- a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
+++ b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
@@ -52,5 +52,5 @@ class DbalLogger implements SQLLogger
@@ -56,5 +56,5 @@ class DbalLogger implements SQLLogger
* @return void
*/
- protected function log(string $message, array $params)
Expand Down Expand Up @@ -502,7 +502,7 @@ index eadeafba55..4f1ca3bfef 100644
{
$configuration = new Configuration();
diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php
index cdbb90a3a9..b137a12012 100644
index 5083538709..82093403f1 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php
@@ -56,5 +56,5 @@ class Application extends BaseApplication
Expand All @@ -512,7 +512,7 @@ index cdbb90a3a9..b137a12012 100644
+ public function reset(): void
{
if ($this->kernel->getContainer()->has('services_resetter')) {
@@ -144,5 +144,5 @@ class Application extends BaseApplication
@@ -145,5 +145,5 @@ class Application extends BaseApplication
* @return void
*/
- protected function registerCommands()
Expand Down Expand Up @@ -4127,20 +4127,20 @@ index 3ea2228b94..f1d7078383 100644
{
return require $file;
diff --git a/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php b/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php
index 084a321ab5..09fb37f3aa 100644
index 9b3709c965..97b54712c9 100644
--- a/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php
+++ b/src/Symfony/Component/DependencyInjection/ContainerAwareInterface.php
@@ -24,4 +24,4 @@ interface ContainerAwareInterface
@@ -26,4 +26,4 @@ interface ContainerAwareInterface
* @return void
*/
- public function setContainer(?ContainerInterface $container);
+ public function setContainer(?ContainerInterface $container): void;
}
diff --git a/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php b/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
index ac67b468c5..bc1e395810 100644
index 4174fec8d0..f6a7b2da12 100644
--- a/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
+++ b/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
@@ -27,5 +27,5 @@ trait ContainerAwareTrait
@@ -31,5 +31,5 @@ trait ContainerAwareTrait
* @return void
*/
- public function setContainer(ContainerInterface $container = null)
Expand Down Expand Up @@ -4698,7 +4698,7 @@ index f610b014a0..9458751c28 100644
+ abstract protected function setNode(\DOMElement $node): void;
}
diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php
index 59eec3068c..b750e80938 100644
index 274aeee5fc..ccf37dae8b 100644
--- a/src/Symfony/Component/DomCrawler/Crawler.php
+++ b/src/Symfony/Component/DomCrawler/Crawler.php
@@ -96,5 +96,5 @@ class Crawler implements \Countable, \IteratorAggregate
Expand Down Expand Up @@ -8236,62 +8236,68 @@ index ed2189e4e7..28e90cdcf9 100644

public function getMetadataBag(): MetadataBag;
diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
index 2ddf55f2cb..52049a92b4 100644
index af21469b1c..7b024368c5 100644
--- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
+++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
@@ -35,5 +35,5 @@ abstract class Bundle implements BundleInterface
@@ -38,5 +38,5 @@ abstract class Bundle implements BundleInterface
* @return void
*/
- public function boot()
+ public function boot(): void
{
}
@@ -42,5 +42,5 @@ abstract class Bundle implements BundleInterface
@@ -45,5 +45,5 @@ abstract class Bundle implements BundleInterface
* @return void
*/
- public function shutdown()
+ public function shutdown(): void
{
}
@@ -52,5 +52,5 @@ abstract class Bundle implements BundleInterface
@@ -55,5 +55,5 @@ abstract class Bundle implements BundleInterface
* @return void
*/
- public function build(ContainerBuilder $container)
+ public function build(ContainerBuilder $container): void
{
}
@@ -122,5 +122,5 @@ abstract class Bundle implements BundleInterface
@@ -125,5 +125,5 @@ abstract class Bundle implements BundleInterface
* @return void
*/
- public function registerCommands(Application $application)
+ public function registerCommands(Application $application): void
{
}
diff --git a/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php b/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
index 02cb9641db..abe408eb24 100644
index fe200629f4..692c41ec53 100644
--- a/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
+++ b/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
@@ -28,5 +28,5 @@ interface BundleInterface extends ContainerAwareInterface
@@ -29,5 +29,5 @@ interface BundleInterface extends ContainerAwareInterface
* @return void
*/
- public function boot();
+ public function boot(): void;

/**
@@ -35,5 +35,5 @@ interface BundleInterface extends ContainerAwareInterface
@@ -36,5 +36,5 @@ interface BundleInterface extends ContainerAwareInterface
* @return void
*/
- public function shutdown();
+ public function shutdown(): void;

/**
@@ -44,5 +44,5 @@ interface BundleInterface extends ContainerAwareInterface
@@ -45,5 +45,5 @@ interface BundleInterface extends ContainerAwareInterface
* @return void
*/
- public function build(ContainerBuilder $container);
+ public function build(ContainerBuilder $container): void;

/**
@@ -72,4 +72,4 @@ interface BundleInterface extends ContainerAwareInterface
* @return void
*/
- public function setContainer(?ContainerInterface $container);
+ public function setContainer(?ContainerInterface $container): void;
}
diff --git a/src/Symfony/Component/HttpKernel/CacheClearer/CacheClearerInterface.php b/src/Symfony/Component/HttpKernel/CacheClearer/CacheClearerInterface.php
index 5ca4265624..1cb3611f8d 100644
--- a/src/Symfony/Component/HttpKernel/CacheClearer/CacheClearerInterface.php
Expand Down Expand Up @@ -8964,7 +8970,7 @@ index 0f3630e7fe..ddf77b8a19 100644
{
return <<<'EOF'
diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php
index 9d4c5f22b3..4030ab8b12 100644
index c2d67c0f17..5c4841305b 100644
--- a/src/Symfony/Component/HttpKernel/Kernel.php
+++ b/src/Symfony/Component/HttpKernel/Kernel.php
@@ -107,5 +107,5 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
Expand Down Expand Up @@ -10911,7 +10917,7 @@ index bde72c0eb0..3d6813e1d4 100644
{
if (!\is_array($config)) {
diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php
index e92a5ea3d7..4a0af31349 100644
index 0e740bdf6c..21b68e3600 100644
--- a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php
+++ b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php
@@ -54,5 +54,5 @@ EOF;
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE-6.4.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
UPGRADE FROM 6.3 to 6.4
=======================

DependencyInjection
-------------------

* Deprecate `ContainerAwareInterface` and `ContainerAwareTrait`, use dependency injection instead

DoctrineBridge
--------------

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

HttpFoundation
--------------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Doctrine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Deprecate `DbalLogger`, use a middleware instead
* Deprecate not constructing `DoctrineDataCollector` with an instance of `DebugDataHolder`
* Deprecate `DoctrineDataCollector::addLogger()`, use a `DebugDataHolder` instead
* Deprecate `ContainerAwareLoader`, use dependency injection in your fixtures instead

6.3
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

trigger_deprecation('symfony/dependency-injection', '6.4', '"%s" is deprecated, use dependency injection in your fixtures instead.', ContainerAwareLoader::class);

/**
* Doctrine data fixtures loader that injects the service container into
* fixture objects that implement ContainerAwareInterface.
*
* Note: Use of this class requires the Doctrine data fixtures extension, which
* is a suggested dependency for Symfony.
*
* @deprecated since Symfony 6.4, use dependency injection in your fixtures instead
*/
class ContainerAwareLoader extends Loader
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Symfony\Bridge\Doctrine\Tests\Fixtures\ContainerAwareFixture;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* @group legacy
*/
class ContainerAwareLoaderTest extends TestCase
{
public function testShouldSetContainerOnContainerAwareFixture()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
class ContainerAwareFixture implements FixtureInterface, ContainerAwareInterface
{
public ?ContainerInterface $container = null;
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function get(string $name): Command
$command = parent::get($name);

if ($command instanceof ContainerAwareInterface) {
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));
$command->setContainer($this->kernel->getContainer());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function instantiateController(string $class): object
$controller = parent::instantiateController($class);

if ($controller instanceof ContainerAwareInterface) {
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));
$controller->setContainer($this->container);
}
if ($controller instanceof AbstractController) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Psr\Container\ContainerInterface as Psr11ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver;
use Symfony\Component\DependencyInjection\Container;
Expand All @@ -23,31 +24,44 @@

class ControllerResolverTest extends ContainerControllerResolverTest
{
use ExpectDeprecationTrait;

/**
* @group legacy
*/
public function testGetControllerOnContainerAware()
{
$resolver = $this->createControllerResolver();
$request = Request::create('/');
$request->attributes->set('_controller', 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController::testAction');

$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.');
$controller = $resolver->getController($request);

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

/**
* @group legacy
*/
public function testGetControllerOnContainerAwareInvokable()
{
$resolver = $this->createControllerResolver();
$request = Request::create('/');
$request->attributes->set('_controller', 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController');

$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.');
$controller = $resolver->getController($request);

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

/**
* @group legacy
*/
public function testContainerAwareControllerGetsContainerWhenNotSet()
{
class_exists(AbstractControllerTest::class);
Expand All @@ -62,6 +76,7 @@ class_exists(AbstractControllerTest::class);
$request = Request::create('/');
$request->attributes->set('_controller', TestAbstractController::class.'::testAction');

$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.');
$this->assertSame([$controller, 'testAction'], $resolver->getController($request));
$this->assertSame($container, $controller->getContainer());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@

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

use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\FragmentUriGeneratorInterface;
use Twig\Environment;

class FragmentController implements ContainerAwareInterface
class FragmentController
{
use ContainerAwareTrait;

public function indexAction(Environment $twig)
{
return new Response($twig->render('fragment.html.twig', ['bar' => new Bar()]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@

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

use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Response;

class ProfilerController implements ContainerAwareInterface
class ProfilerController
{
use ContainerAwareTrait;

public function indexAction()
{
return new Response('Hello');
Expand Down
Loading