@@ -16,8 +16,7 @@ to be used for a specific purpose. Take the following example:
1616
1717 # app/config/services.yml
1818 services :
19- app.twig_extension :
20- class : AppBundle\Twig\AppExtension
19+ AppBundle\Twig\AppExtension :
2120 public : false
2221 tags : [twig.extension]
2322
@@ -31,11 +30,7 @@ to be used for a specific purpose. Take the following example:
3130 http://symfony.com/schema/dic/services/services-1.0.xsd" >
3231
3332 <services >
34- <service
35- id =" app.twig_extension"
36- class =" AppBundle\Twig\AppExtension"
37- public =" false" >
38-
33+ <service id =" AppBundle\Twig\AppExtension" public =" false" >
3934 <tag name =" twig.extension" />
4035 </service >
4136 </services >
@@ -45,16 +40,14 @@ to be used for a specific purpose. Take the following example:
4540
4641 // app/config/services.php
4742 use AppBundle\Twig\AppExtension;
48- use Symfony\Component\DependencyInjection\Definition;
4943
50- $definition = new Definition(AppExtension::class);
51- $definition->setPublic(false);
52- $definition->addTag('twig.extension');
53- $container->setDefinition('app.twig_extension', $definition);
44+ $container->register(AppExtension::class)
45+ ->setPublic(false)
46+ ->addTag('twig.extension');
5447
5548 The ``twig.extension `` tag is a special tag that the TwigBundle uses
5649during configuration. By giving the service this ``twig.extension `` tag,
57- the bundle knows that the ``app.twig_extension `` service should be registered
50+ the bundle knows that the ``AppExtension::class `` service should be registered
5851as a Twig extension with Twig. In other words, Twig finds all services tagged
5952with ``twig.extension `` and automatically registers them as extensions.
6053
@@ -359,10 +352,31 @@ To answer this, change the service declaration:
359352 tags :
360353 - { name: app.mail_transport }
361354
362- versionadded:: 3.3
355+ .. versionadded :: 3.3
363356 Support for the compact tag notation in the YAML format was introduced
364357 in Symfony 3.3.
365358
359+ .. tip ::
360+
361+ In YAML format, you may define a service with a simple array of tags as long
362+ as you don't need additional attributes. The following definitions are
363+ equivalent.
364+
365+ .. code-block :: yaml
366+
367+ services :
368+
369+ # Compact syntax
370+ AppBundle\Twig\AppExtension : [twig.extension]
371+
372+ # Verbose syntax
373+ AppBundle\Twig\AppExtension :
374+ tags : [twig.extension]
375+
376+ .. versionadded :: 3.3
377+ Support for the short syntax for service definition in the YAML format
378+ was introduced in Symfony 3.3.
379+
366380Notice that you've added a generic ``alias `` key to the tag. To actually
367381use this, update the compiler::
368382
0 commit comments