Skip to content

Commit 09e5f63

Browse files
committed
[DI] Add some documentation for the deprecation feature
1 parent f8c9ce3 commit 09e5f63

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

components/dependency_injection/advanced.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,64 @@ 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+
The message is actually a message template, which will replace occurrences
254+
of the ``%service_id%`` by the service's id. You **must** have at least one
255+
occurrence of the ``%service_id%`` placeholder in your template.
256+
257+
.. note::
258+
259+
The deprecation message is optional. If not set, Symfony will show a default
260+
message ``The "%service_id%" service is deprecated. You should stop using it,
261+
as it will soon be removed.``.
262+
263+
.. tip::
264+
265+
It is strongly recommended that you fill the message template, to avoid a
266+
message that could be too generic such as the default one. A good message
267+
informs when this service was deprecated, and until when it will be
268+
maintained (look at the examples above).
269+
270+
For service decorators (see above), if the definition does not modify the
271+
deprecated status, it will inherit the status from the definition that is
272+
decorated.
273+
274+
.. caution::
275+
276+
The ability to "un-deprecate" a service is possible only when declaring the
277+
definition in PHP.
278+
279+
.. versionadded:: 2.8
280+
281+
The `deprecated` setting was added in 2.8

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