-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[DI] Add some documentation for the deprecation feature #5689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,3 +218,63 @@ You can change the inner service name if you want to: | |
->addArgument(new Reference('bar.wooz')) | ||
->setPublic(false) | ||
->setDecoratedService('foo', 'bar.wooz'); | ||
|
||
Deprecating Services | ||
-------------------- | ||
.. versionadded:: 2.8 | ||
The ``deprecated`` setting was introduced in Symfony 2.8 | ||
|
||
Once you have decided to deprecate the use of a service (because it is outdated | ||
or you decided not to use and maintain it anymore), you can deprecate its | ||
definition: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
bar: | ||
class: stdClass | ||
deprecated: The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0. | ||
|
||
.. code-block:: xml | ||
|
||
<service id="bar" class="stdClass"> | ||
<deprecated>The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0.</deprecated> | ||
</service> | ||
|
||
.. code-block:: php | ||
|
||
$container | ||
->register('bar', 'stdClass') | ||
->setDeprecated(true, 'The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0.'); | ||
|
||
Now, every time a service is created using this deprecated definition, a | ||
deprecation warning will be triggered, advising you to stop or to change your | ||
uses of that service. | ||
|
||
The message is actually a message template, which will replace occurrences | ||
of the ``%service_id%`` by the service's id. You **must** have at least one | ||
occurrence of the ``%service_id%`` placeholder in your template. | ||
|
||
.. note:: | ||
|
||
The deprecation message is optional. If not set, Symfony will show a default | ||
message ``The "%service_id%" service is deprecated. You should stop using it, | ||
as it will soon be removed.``. | ||
|
||
.. tip:: | ||
|
||
It is strongly recommended that you fill the message template, to avoid a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is actually more a tip directive imo. Can you change this to be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I leave the note on the first paragraph or transform everything as a tip ? IMO the first paragraph belongs in a note, but then it could be weird to have two special blocks one after another... |
||
message that could be too generic such as the default one. A good message | ||
informs when this service was deprecated, and until when it will be | ||
maintained (look at the examples above). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can improve this part somehow. The content is good, but having three consecutive note containers looks a bit weird. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was also what I was thinking but I somehow can't bring myself to decide to merge these 3 notes as they are really going on different subjects... any suggestion would be welcomed though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, merging these 3 containers should also look good. But I would welcome any suggestions too ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could merge the first two note blocks and include the third one in the regular paragraph. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems fair, I'll try to do that in the following hours. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to have the 3 notes blocks fused into one, as they are all about the same thing (the "optionnal" status of the message, and the fact that it is recommended to provide one) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done @xabbuh |
||
|
||
For service decorators (see above), if the definition does not modify the | ||
deprecated status, it will inherit the status from the definition that is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain what you mean with "deprecated status" and how it could be modified? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can now only be modified with PHP (through manipulation of the But maybe I should remove this part altogether ? As it is really a edge case that should not be recommended... |
||
decorated. | ||
|
||
.. caution:: | ||
|
||
The ability to "un-deprecate" a service is possible only when declaring the | ||
definition in PHP. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a blank line after this one (same below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed