Skip to content

Documented short DI tag syntax #7769

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

Merged
merged 1 commit into from
Apr 8, 2017
Merged
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
29 changes: 23 additions & 6 deletions service_container/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ to be used for a specific purpose. Take the following example:
app.twig_extension:
class: AppBundle\Twig\AppExtension
public: false
tags:
- { name: twig.extension }
tags: [twig.extension]

.. code-block:: xml

Expand Down Expand Up @@ -148,13 +147,11 @@ For example, you may add the following transports as services:
app.smtp_transport:
class: \Swift_SmtpTransport
arguments: ['%mailer_host%']
tags:
- { name: app.mail_transport }
tags: [app.mail_transport]

app.sendmail_transport:
class: \Swift_SendmailTransport
tags:
- { name: app.mail_transport }
tags: [app.mail_transport]

.. code-block:: xml

Expand Down Expand Up @@ -341,6 +338,26 @@ To answer this, change the service declaration:
$definitionSendmail->addTag('app.mail_transport', array('alias' => 'bar'));
$container->setDefinition('app.sendmail_transport', $definitionSendmail);

.. tip::

In YAML format, you may provide the tag as a simple string as long as you don't need to specify additional
attributes. The following definitions are equivalent.

.. code-block:: yaml

services:

# Compact syntax
app.sendmail_transport:
class: \Swift_SendmailTransport
tags: [app.mail_transport]

# Verbose syntax
app.sendmail_transport:
class: \Swift_SendmailTransport
tags:
- { name: app.mail_transport }

Notice that you've added a generic ``alias`` key to the tag. To actually
use this, update the compiler::

Expand Down