8000 minor #10937 Documented the deprecation of service aliases (javieregu… · symfony/symfony-docs@32ec45d · GitHub
[go: up one dir, main page]

Skip to content

Commit 32ec45d

Browse files
committed
minor #10937 Documented the deprecation of service aliases (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #10937). Discussion ---------- Documented the deprecation of service aliases It documents symfony/symfony#29968 but it contains the changes of the pending PR symfony/symfony#29995 Commits ------- d5d87e6 Documented the deprecation of service aliases
2 parents 25362d9 + d5d87e6 commit 32ec45d

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

service_container/alias_private.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,69 @@ 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+
$container
189+
->setAlias('app.mailer', 'App\Mail\PhpMailer')
190+
191+
// this will display a generic deprecation message...
192+
->setDeprecated(true)
193+
194+
// ...but you can also define a custom deprecation message
195+
->setDeprecated(
196+
true,
197+
'The "%alias_id%" service alias is deprecated. Don\'t use it anymore.'
198+
)
199+
;
200+
201+
Now, every time this service alias is used, a deprecation warning is triggered,
202+
advising you to stop or to change your uses of that alias.
203+
204+
The message is actually a message template, which replaces occurrences of the
205+
``%alias_id%`` placeholder by the service alias id. You **must** have at least
206+
one occurrence of the ``%alias_id%`` placeholder in your template.
207+
208+
.. versionadded:: 4.3
209+
210+
The ``deprecated`` option for service aliases was introduced in Symfony 4.3.
211+
149212
Anonymous Services
150213
------------------
151214

0 commit comments

Comments
 (0)
0