Skip to content

Commit 7849331

Browse files
committed
feature #7769 Documented short DI tag syntax (derrabus)
This PR was merged into the master branch. Discussion ---------- Documented short DI tag syntax This PR fixes #7248 and documents the short DI tag syntax for YAML files. Commits ------- f5b1f23 Documented short DI tag syntax.
2 parents ad90ec7 + f5b1f23 commit 7849331

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

service_container/tags.rst

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ to be used for a specific purpose. Take the following example:
1919
app.twig_extension:
2020
class: AppBundle\Twig\AppExtension
2121
public: false
22-
tags:
23-
- { name: twig.extension }
22+
tags: [twig.extension]
2423
2524
.. code-block:: xml
2625
@@ -148,13 +147,11 @@ For example, you may add the following transports as services:
148147
app.smtp_transport:
149148
class: \Swift_SmtpTransport
150149
arguments: ['%mailer_host%']
151-
tags:
152-
- { name: app.mail_transport }
150+
tags: [app.mail_transport]
153151
154152
app.sendmail_transport:
155153
class: \Swift_SendmailTransport
156-
tags:
157-
- { name: app.mail_transport }
154+
tags: [app.mail_transport]
158155
159156
.. code-block:: xml
160157
@@ -341,6 +338,26 @@ To answer this, change the service declaration:
341338
$definitionSendmail->addTag('app.mail_transport', array('alias' => 'bar'));
342339
$container->setDefinition('app.sendmail_transport', $definitionSendmail);
343340
341+
.. tip::
342+
343+
In YAML format, you may provide the tag as a simple string as long as you don't need to specify additional
344+
attributes. The following definitions are equivalent.
345+
346+
.. code-block:: yaml
347+
348+
services:
349+
350+
# Compact syntax
351+
app.sendmail_transport:
352+
class: \Swift_SendmailTransport
353+
tags: [app.mail_transport]
354+
355+
# Verbose syntax
356+
app.sendmail_transport:
357+
class: \Swift_SendmailTransport
358+
tags:
359+
- { name: app.mail_transport }
360+
344361
Notice that you've added a generic ``alias`` key to the tag. To actually
345362
use this, update the compiler::
346363

0 commit comments

Comments
 (0)