Skip to content

Commit ca42b69

Browse files
committed
Clarify goals of AbstractController
1 parent 6a56e50 commit ca42b69

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +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
1011

1112
5.3
1213
---

Controller/AbstractController.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use Twig\Environment;
5151

5252
/**
53-
* Provides common features needed in controllers.
53+
* Provides shortcuts for HTTP-related features in controllers.
5454
*
5555
* @author Fabien Potencier <[email protected]>
5656
*/
@@ -370,9 +370,13 @@ protected function createFormBuilder($data = null, array $options = []): FormBui
370370
* Shortcut to return the Doctrine Registry service.
371371
*
372372
* @throws \LogicException If DoctrineBundle is not available
373+
*
374+
* @deprecated since 5.4, inject an instance of ManagerRegistry in your controller instead
373375
*/
374376
protected function getDoctrine(): ManagerRegistry
375377
{
378+
trigger_deprecation('symfony/framework-bundle', '5.4', 'Method "%s()" is deprecated, inject an instance of ManagerRegistry in your controller instead.', __METHOD__);
379+
376380
if (!$this->container->has('doctrine')) {
377381
throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
378382
}
@@ -426,9 +430,13 @@ protected function isCsrfTokenValid(string $id, ?string $token): bool
426430
* Dispatches a message to the bus.
427431
*
428432
* @param object|Envelope $message The message or the message pre-wrapped in an envelope
433+
*
434+
* @deprecated since 5.4, inject an instance of MessageBusInterface in your controller instead
429435
*/
430436
protected function dispatchMessage(object $message, array $stamps = []): Envelope
431437
{
438+
trigger_deprecation('symfony/framework-bundle', '5.4', 'Method "%s()" is deprecated, inject an instance of MessageBusInterface in your controller instead.', __METHOD__);
439+
432440
if (!$this->container->has('messenger.default_bus')) {
433441
$message = class_exists(Envelope::class) ? 'You need to define the "messenger.default_bus" configuration option.' : 'Try running "composer require symfony/messenger".';
434442
throw new \LogicException('The message bus is not enabled in your application. '.$message);

0 commit comments

Comments
 (0)