From 104c8f9302efa0fe7c3ee08c5a0cb0d7810d7abd Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 28 Jan 2019 17:20:29 +0100 Subject: [PATCH 1/2] Documented the deprecation of service aliases --- service_container/alias_private.rst | 65 +++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/service_container/alias_private.rst b/service_container/alias_private.rst index 756ab691b68..a1b90866540 100644 --- a/service_container/alias_private.rst +++ b/service_container/alias_private.rst @@ -146,6 +146,71 @@ This means that when using the container directly, you can access the # ... app.mailer: '@App\Mail\PhpMailer' +Deprecating Service Aliases +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you decide to deprecate the use of a service alias (because it is outdated +or you decided not to maintain it anymore), you can deprecate its definition: + +.. configuration-block:: + + .. code-block:: yaml + + app.mailer: + alias: '@AppBundle\Mail\PhpMailer' + + # this will display a generic deprecation message... + deprecated: true + + # ...but you can also define a custom deprecation message + deprecated: 'The "%alias_id%" alias is deprecated. Don't use it anymore.' + + .. code-block:: xml + + + + + + + + + + + The "%alias_id%" service alias is deprecated. Don't use it anymore. + + + + + .. code-block:: php + + use AppBundle\Service\OldService; + + $container + ->setAlias('app.mailer', 'App\Mail\PhpMailer') + + // this will display a generic deprecation message... + ->setDeprecated(true) + + // ...but you can also define a custom deprecation message + ->setDeprecated( + true, + 'The "%alias_id%" service alias is deprecated. Don\'t use it anymore.' + ) + ; + +Now, every time this service alias is used, a deprecation warning is triggered, +advising you to stop or to change your uses of that alias. + +The message is actually a message template, which replaces occurrences of the +``%alias_id%`` placeholder by the service alias id. You **must** have at least +one occurrence of the ``%alias_id%`` placeholder in your template. + +.. versionadded:: 4.3 + + The ``deprecated`` option for service aliases was introduced in Symfony 4.3. + Anonymous Services ------------------ From f3ade6d6de7597fe9daf8a488a09bfd45b6be9b7 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 29 Jan 2019 08:49:55 +0100 Subject: [PATCH 2/2] Fixes --- service_container/alias_private.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/service_container/alias_private.rst b/service_container/alias_private.rst index a1b90866540..eda3658c778 100644 --- a/service_container/alias_private.rst +++ b/service_container/alias_private.rst @@ -163,7 +163,7 @@ or you decided not to maintain it anymore), you can deprecate its definition: deprecated: true # ...but you can also define a custom deprecation message - deprecated: 'The "%alias_id%" alias is deprecated. Don't use it anymore.' + deprecated: 'The "%alias_id%" alias is deprecated. Don\'t use it anymore.' .. code-block:: xml @@ -185,8 +185,6 @@ or you decided not to maintain it anymore), you can deprecate its definition: .. code-block:: php - use AppBundle\Service\OldService; - $container ->setAlias('app.mailer', 'App\Mail\PhpMailer')