Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions service_container/alias_private.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,69 @@ 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

$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
------------------

Expand Down