Skip to content

Commit 4d71811

Browse files
committed
Documented the deprecation of service aliases
1 parent 5bb148e commit 4d71811

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

service_container/alias_private.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,71 @@ This means that when using the container directly, you can access the
146146
# ...
147147
app.mailer: '@App\Mail\PhpMailer'
148148
149+
Deprecating Service Aliases
150+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
151+
152+
If you decide to deprecate the use of a service alias (because it is outdated
153+
or you decided not to maintain it anymore), you can deprecate its definition:
154+
155+
.. configuration-block::
156+
157+
.. code-block:: yaml
158+
159+
app.mailer:
160+
alias: '@AppBundle\Mail\PhpMailer'
161+
162+
# this will display a generic deprecation message...
163+
deprecated: true
164+
165+
# ...but you can also define a custom deprecation message
166+
deprecated: 'The "%alias_id%" alias is deprecated. Don't use it anymore.'
167+
168+
.. code-block:: xml
169+
170+
<?xml version="1.0" encoding="UTF-8" ?>
171+
<container xmlns="http://symfony.com/schema/dic/services"
172+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
173+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
174+
175+
<services>
176+
<service id="app.mailer" alias="App\Mail\PhpMailer">
177+
<!-- this will display a generic deprecation message... -->
178+
<deprecated />
179+
180+
<!-- ...but you can also define a custom deprecation message -->
181+
<deprecated>The "%alias_id%" service alias is deprecated. Don't use it anymore.</deprecated>
182+
</service>
183+
</services>
184+
</container>
185+
186+
.. code-block:: php
187+
188+
use AppBundle\Service\OldService;
189+
190+
$container
191+
->setAlias('app.mailer', 'App\Mail\PhpMailer')
192+
193+
// this will display a generic deprecation message...
194+
->setDeprecated(true)
195+
196+
// ...but you can also define a custom deprecation message
197+
->setDeprecated(
198+
true,
199+
'The "%alias_id%" service alias is deprecated. Don\'t use it anymore.'
200+
)
201+
;
202+
203+
Now, every time this service alias is used, a deprecation warning is triggered,
204+
advising you to stop or to change your uses of that alias.
205+
206+
The message is actually a message template, which replaces occurrences of the
207+
``%alias_id%`` placeholder by the service alias id. You **must** have at least
208+
one occurrence of the ``%alias_id%`` placeholder in your template.
209+
210+
.. versionadded:: 4.3
211+
212+
The ``deprecated`` option for service aliases was introduced in Symfony 4.3.
213+
149214
Anonymous Services
150215
------------------
151216

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy