-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Documented the deprecation of service aliases #10937
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Documented the deprecation of service aliases
- Loading branch information
commit 104c8f9302efa0fe7c3ee08c5a0cb0d7810d7abd
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,71 @@ This means that when using the container directly, you can access the | |
# ... | ||
app.mailer: '@App\Mail\PhpMailer' | ||
|
||
Deprecating Service Aliases | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
If you decide to deprecate the use of a service alias (because it is outdated | ||
or you decided not to maintain it anymore), you can deprecate its definition: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
app.mailer: | ||
alias: '@AppBundle\Mail\PhpMailer' | ||
|
||
# this will display a generic deprecation message... | ||
deprecated: true | ||
|
||
# ...but you can also define a custom deprecation message | ||
deprecated: 'The "%alias_id%" alias is deprecated. Don't use it anymore.' | ||
|
||
.. code-block:: xml | ||
|
||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service id="app.mailer" alias="App\Mail\PhpMailer"> | ||
<!-- this will display a generic deprecation message... --> | ||
<deprecated /> | ||
|
||
<!-- ...but you can also define a custom deprecation message --> | ||
<deprecated>The "%alias_id%" service alias is deprecated. Don't use it anymore.</deprecated> | ||
</service> | ||
</services> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
use AppBundle\Service\OldService; | ||
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 OldService is not used in the example |
||
|
||
$container | ||
->setAlias('app.mailer', 'App\Mail\PhpMailer') | ||
|
||
// this will display a generic deprecation message... | ||
->setDeprecated(true) | ||
|
||
// ...but you can also define a custom deprecation message | ||
->setDeprecated( | ||
true, | ||
'The "%alias_id%" service alias is deprecated. Don\'t use it anymore.' | ||
) | ||
; | ||
|
||
Now, every time this service alias is used, a deprecation warning is triggered, | ||
advising you to stop or to change your uses of that alias. | ||
|
||
The message is actually a message template, which replaces occurrences of the | ||
``%alias_id%`` placeholder by the service alias id. You **must** have at least | ||
one occurrence of the ``%alias_id%`` placeholder in your template. | ||
|
||
.. versionadded:: 4.3 | ||
|
||
The ``deprecated`` option for service aliases was introduced in Symfony 4.3. | ||
|
||
Anonymous Services | ||
------------------ | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The quote in
Don't
should be escaped