@@ -146,6 +146,71 @@ This means that when using the container directly, you can access the
146
146
# ...
147
147
app.mailer : ' @App\Mail\PhpMailer'
148
148
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
+
149
214
Anonymous Services
150
215
------------------
151
216
0 commit comments