You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #42442 [FrameworkBundle] Deprecate AbstractController::get() and has() (fabpot)
This PR was merged into the 5.4 branch.
Discussion
----------
[FrameworkBundle] Deprecate AbstractController::get() and has()
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets | n/a <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License | MIT
| Doc PR | n/a
Controllers extending `AbstractController` have access to the services registered for the shortcuts defined in `AbstractController` via `get()` and `has()`. These methods can make developers think that they have access to the whole container, which is not true. Moreover, the limited set of services are precisely the ones needed for the shortcuts, so probably not the ones people would need anyway.
I propose to deprecate these methods and advocate using method/constructor injection instead.
If people want to still use the container, they can access it via the `$this->container` property (useful if they extend `getSubscribedServices()` for instance).
Commits
-------
66a81eadad [FrameworkBundle] Deprecate AbstractController::get() and has()
'message_bus' => '?'.MessageBusInterface::class,// to be removed in 6.0
105
+
'messenger.default_bus' => '?'.MessageBusInterface::class,// to be removed in 6.0
106
106
];
107
107
}
108
108
109
109
/**
110
110
* Returns true if the service id is defined.
111
+
*
112
+
* @deprecated since 5.4, use method or constructor injection in your controller instead
111
113
*/
112
114
protectedfunctionhas(string$id): bool
113
115
{
116
+
trigger_deprecation('symfony/framework-bundle', '5.4', 'Method "%s()" is deprecated, use method or constructor injection in your controller instead.', __METHOD__);
117
+
114
118
return$this->container->has($id);
115
119
}
116
120
117
121
/**
118
122
* Gets a container service by its id.
119
123
*
120
124
* @return object The service
125
+
*
126
+
* @deprecated since 5.4, use method or constructor injection in your controller instead
121
127
*/
122
128
protectedfunctionget(string$id): object
123
129
{
130
+
trigger_deprecation('symfony/framework-bundle', '5.4', 'Method "%s()" is deprecated, use method or constructor injection in your controller instead.', __METHOD__);
0 commit comments