8000 [FrameworkBundle] Deprecate auto-injection of the container in AbstractController instances by nicolas-grekas · Pull Request #27462 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Deprecate auto-injection of the container in AbstractController instances #27462

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 1 commit into from
Jun 4, 2018
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
[FrameworkBundle] Deprecate auto-injection of the container in Abstra…
…ctController instances
  • Loading branch information
nicolas-grekas committed Jun 4, 2018
commit e2f344fa322a0b3c3bb7d8cf67ab9ba7a615b750
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
-----

* Allowed configuring taggable cache pools via a new `framework.cache.pools.tags` option (bool|service-id)
* Deprecated auto-injection of the container in AbstractController instances, register them as service subscribers instead

4.1.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,22 @@ protected function createController($controller)
*/
protected function instantiateController($class)
{
return $this->configureController(parent::instantiateController($class));
return $this->configureController(parent::instantiateController($class), $class);
}

private function configureController($controller)
private function configureController($controller, string $class)
{
if ($controller instanceof ContainerAwareInterface) {
$controller->setContainer($this->container);
}
if ($controller instanceof AbstractController && null !== $previousContainer = $controller->setContainer($this->container)) {
$controller->setContainer($previousContainer);
if ($controller instanceof AbstractController) {
if (null === $previousContainer = $controller->setContainer($this->container)) {
@trigger_error(sprintf('Auto-injection of the container for "%s" is deprecated since Symfony 4.2. Configure it as a service instead.', $class), E_USER_DEPRECATED);
// To be uncommented on Symfony 5:
//throw new \LogicException(sprintf('"%s" has no container set, did you forget to define it as a service subscriber?', $class));
} else {
$controller->setContainer($previousContainer);
}
}

return $controller;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class_exists(AbstractControllerTest::class);
$this->assertSame($container, $controller->getContainer());
}

/**
* @group legacy
* @expectedDeprecation Auto-injection of the container for "Symfony\Bundle\FrameworkBundle\Tests\Controller\TestAbstractController" is deprecated since Symfony 4.2. Configure it as a service instead.
*/
public function testAbstractControllerGetsContainerWhenNotSet()
{
class_exists(AbstractControllerTest::class);
Expand All @@ -110,6 +114,10 @@ class_exists(AbstractControllerTest::class);
$this->assertSame($container, $controller->setContainer($container));
}

/**
* @group legacy
* @expectedDeprecation Auto-injection of the container for "Symfony\Bundle\FrameworkBundle\Tests\Controller\DummyController" is deprecated since Symfony 4.2. Configure it as a service instead.
*/
public function testAbstractControllerServiceWithFcqnIdGetsContainerWhenNotSet()
{
class_exists(AbstractControllerTest::class);
Expand Down
0