@@ -218,3 +218,58 @@ You can change the inner service name if you want to:
218218 ->addArgument(new Reference('bar.wooz'))
219219 ->setPublic(false)
220220 ->setDecoratedService('foo', 'bar.wooz');
221+
222+ Deprecating Services
223+ --------------------
224+
225+ Once you have decided to deprecate the use of a service (because it is outdated
226+ or you decided not to use and maintain it anymore), you can deprecate its
227+ definition:
228+
229+ .. configuration-block ::
230+
231+ .. code-block :: yaml
232+
233+ bar :
234+ class : stdClass
235+ deprecated : The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0.
236+
237+ .. code-block :: xml
238+
239+ <service id =" bar" class =" stdClass" >
240+ <deprecated >The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0.</deprecated >
241+ </service >
242+
243+ .. code-block :: php
244+
245+ $container
246+ ->register('bar', 'stdClass')
247+ ->setDeprecated(true, 'The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0.');
248+
249+ Now, every time a service is created using this deprecated definition, a
250+ deprecation warning will be triggered, advising you to stop or to change your
251+ uses of that service.
252+
253+ .. note ::
254+
255+ The deprecation message is optional. If not set, Symfony will show a default
256+ message ``The "%service_id%" service is deprecated. You should stop using it,
257+ as it will soon be removed. ``.
258+
259+ The message is actually a message template, which will replace occurrences
260+ of the ``%service_id% `` by the service's id. You **must ** have at least one
261+ occurrence of the ``%service_id% `` placeholder in your template.
262+
263+ It is strongly recommended that you fill the message template, to avoid a
264+ message that could be too generic such as the default one. A good message
265+ informs when this service was deprecated, and until when it will be
266+ maintained (look at the examples above).
267+
268+ For service decorators (see above), if the definition does not modify the
269+ deprecated status, it will inherit the status from the definition that is
270+ decorated.
271+
272+ .. warning ::
273+
274+ The ability to "undeprecate" a service is possible only while declaring the
275+ definition in PHP.
0 commit comments