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