Skip to content

Commit cebdb1b

Browse files
committed
[DI] Add some documentation for the deprecation feature
1 parent de141d5 commit cebdb1b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

components/dependency_injection/advanced.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,54 @@ 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: true
236+
deprecation_message: The '%service_id%' service is deprecated. You should stop using it, as it will soon be removed.
237+
238+
.. code-block:: xml
239+
240+
<service id="bar" class="stdClass">
241+
<deprecated>The '%service_id%' service is deprecated. You should stop using it, as it will soon be removed.</deprecated>
242+
</service>
243+
244+
.. code-block:: php
245+
246+
$container->register('bar', 'stdClass')
247+
->setDeprecated(true, 'The \'%service_id%\' service is deprecated. You should stop using it, as it will soon be removed.');
248+
249+
Now, every time a service is created using this deprecated definition will
250+
trigger a deprecation error, advising you to stop or change your uses of that
251+
service.
252+
253+
.. note::
254+
The deprecation message is optional. If not set, Symfony will show a default
255+
message ``The '%service_id%' service is deprecated. You should stop using it,
256+
as it will soon be removed.``.
257+
258+
.. note::
259+
The message is actually a template message, which will replace occurrences
260+
of ``%service_id%`` by the service's id. You **must** have at least one
261+
occurrence of ``%service_id%`` in your template message.
262+
263+
.. note::
264+
We really recommand you to fill the template message, to avoid a message that
265+
could be too generic such as the default one. A good message explains
266+
(shortly) why this service was deprecated, from which version and until when
267+
it will be maintained.
268+
269+
For services decorators (see above), if the definition does not modify the
270+
deprecated status, it will inherit the status from the definition that is
271+
decorated.

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