Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7dc4f5d

Browse files
committed
[DI] Add some documentation for the deprecation feature
1 parentde141d5 commit7dc4f5d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

‎components/dependency_injection/advanced.rst

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp