From f3a672118caa64290f559a41925b9eaa19392c0f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 8 Aug 2021 09:52:38 +0200 Subject: [PATCH] Clarify goals of AbstractController --- UPGRADE-5.4.md | 1 + UPGRADE-6.0.md | 1 + src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../FrameworkBundle/Controller/AbstractController.php | 10 +++++++++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/UPGRADE-5.4.md b/UPGRADE-5.4.md index e547f86b1e05f..072cf6fe205ad 100644 --- a/UPGRADE-5.4.md +++ b/UPGRADE-5.4.md @@ -17,6 +17,7 @@ FrameworkBundle * Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead * Deprecate the public `profiler` service to private + * Deprecate `getDoctrine()` and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead HttpKernel ---------- diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index bb5863fb304f2..f67fa0b1f8509 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -101,6 +101,7 @@ FrameworkBundle * Remove option `--xliff-version` of the `translation:update` command, use e.g. `--output-format=xlf20` instead * Remove option `--output-format` of the `translation:update` command, use e.g. `--output-format=xlf20` instead * Remove the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead + * Remove `getDoctrine()` and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead HttpFoundation -------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index ee3a172397652..31c73f3661b93 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -7,6 +7,7 @@ CHANGELOG * Add autowiring alias for `HttpCache\StoreInterface` * Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead * Deprecate the public `profiler` service to private + * Deprecate `getDoctrine()` and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead 5.3 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index ec815abd323d1..f78314d3922cd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -50,7 +50,7 @@ use Twig\Environment; /** - * Provides common features needed in controllers. + * Provides shortcuts for HTTP-related features in controllers. * * @author Fabien Potencier */ @@ -370,9 +370,13 @@ protected function createFormBuilder($data = null, array $options = []): FormBui * Shortcut to return the Doctrine Registry service. * * @throws \LogicException If DoctrineBundle is not available + * + * @deprecated since 5.4, inject an instance of ManagerRegistry in your controller instead */ protected function getDoctrine(): ManagerRegistry { + trigger_deprecation('symfony/framework-bundle', '5.4', 'Method "%s()" is deprecated, inject an instance of ManagerRegistry in your controller instead.', __METHOD__); + if (!$this->container->has('doctrine')) { throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".'); } @@ -426,9 +430,13 @@ protected function isCsrfTokenValid(string $id, ?string $token): bool * Dispatches a message to the bus. * * @param object|Envelope $message The message or the message pre-wrapped in an envelope + * + * @deprecated since 5.4, inject an instance of MessageBusInterface in your controller instead */ protected function dispatchMessage(object $message, array $stamps = []): Envelope { + trigger_deprecation('symfony/framework-bundle', '5.4', 'Method "%s()" is deprecated, inject an instance of MessageBusInterface in your controller instead.', __METHOD__); + if (!$this->container->has('messenger.default_bus')) { $message = class_exists(Envelope::class) ? 'You need to define the "messenger.default_bus" configuration option.' : 'Try running "composer require symfony/messenger".'; throw new \LogicException('The message bus is not enabled in your application. '.$message);