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

Appearance settings

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 1 commit
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
Next Next commit
Documented the deprecation of service aliases
  • Loading branch information
javiereguiluz committed Jan 28, 2019
commit 104c8f9302efa0fe7c3ee08c5a0cb0d7810d7abd
65 changes: 65 additions & 0 deletions 65 service_container/alias_private.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Copy link
Contributor

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


.. 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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.