From f5b1f23b7bec02a309780d47378645eec5a2a33a Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 8 Apr 2017 11:24:10 +0200 Subject: [PATCH] Documented short DI tag syntax. --- service_container/tags.rst | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/service_container/tags.rst b/service_container/tags.rst index 75bd17607ec..34e2145853b 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -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 @@ -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 @@ -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:: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy