Skip to content

Commit b529455

Browse files
committed
[FrameworkBundle] Deprecate AbstractController::get() and has()
1 parent ca42b69 commit b529455

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CHANGELOG
77
* Add autowiring alias for `HttpCache\StoreInterface`
88
* Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead
99
* Deprecate the public `profiler` service to private
10-
* Deprecate `getDoctrine()` and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead
10+
* Deprecate `get()`, `has()`, `getDoctrine()`, and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead
1111

1212
5.3
1313
---

Controller/AbstractController.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,39 @@ public static function getSubscribedServices()
9696
'session' => '?'.SessionInterface::class,
9797
'security.authorization_checker' => '?'.AuthorizationCheckerInterface::class,
9898
'twig' => '?'.Environment::class,
99-
'doctrine' => '?'.ManagerRegistry::class,
99+
'doctrine' => '?'.ManagerRegistry::class, // to be removed in 6.0
100100
'form.factory' => '?'.FormFactoryInterface::class,
101101
'security.token_storage' => '?'.TokenStorageInterface::class,
102102
'security.csrf.token_manager' => '?'.CsrfTokenManagerInterface::class,
103103
'parameter_bag' => '?'.ContainerBagInterface::class,
104-
'message_bus' => '?'.MessageBusInterface::class,
105-
'messenger.default_bus' => '?'.MessageBusInterface::class,
104+
'message_bus' => '?'.MessageBusInterface::class, // to be removed in 6.0
105+
'messenger.default_bus' => '?'.MessageBusInterface::class, // to be removed in 6.0
106106
];
107107
}
108108

109109
/**
110110
* Returns true if the service id is defined.
111+
*
112+
* @deprecated since 5.4, use method or constructor injection in your controller instead
111113
*/
112114
protected function has(string $id): bool
113115
{
116+
trigger_deprecation('symfony/framework-bundle', '5.4', 'Method "%s()" is deprecated, use method or constructor injection in your controller instead.', __METHOD__);
117+
114118
return $this->container->has($id);
115119
}
116120

117121
/**
118122
* Gets a container service by its id.
119123
*
120124
* @return object The service
125+
*
126+
* @deprecated since 5.4, use method or constructor injection in your controller instead
121127
*/
122128
protected function get(string $id): object
123129
{
130+
trigger_deprecation('symfony/framework-bundle', '5.4', 'Method "%s()" is deprecated, use method or constructor injection in your controller instead.', __METHOD__);
131+
124132
return $this->container->get($id);
125133
}
126134

Tests/Controller/AbstractControllerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ public function testCreateFormBuilder()
601601
$this->assertEquals($formBuilder, $controller->createFormBuilder('foo'));
602602
}
603603

604+
/**
605+
* @group legacy
606+
*/
604607
public function testGetDoctrine()
605608
{
606609
$doctrine = $this->createMock(ManagerRegistry::class);

0 commit comments

Comments
 (0)