@@ -16,8 +16,7 @@ to be used for a specific purpose. Take the following example:
16
16
17
17
# app/config/services.yml
18
18
services :
19
- app.twig_extension :
20
- class : AppBundle\Twig\AppExtension
19
+ AppBundle\Twig\AppExtension :
21
20
public : false
22
21
tags : [twig.extension]
23
22
@@ -31,11 +30,7 @@ to be used for a specific purpose. Take the following example:
31
30
http://symfony.com/schema/dic/services/services-1.0.xsd" >
32
31
33
32
<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" >
39
34
<tag name =" twig.extension" />
40
35
</service >
41
36
</services >
@@ -45,16 +40,14 @@ to be used for a specific purpose. Take the following example:
45
40
46
41
// app/config/services.php
47
42
use AppBundle\Twig\AppExtension;
48
- use Symfony\Component\DependencyInjection\Definition;
49
43
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');
54
47
55
48
The ``twig.extension `` tag is a special tag that the TwigBundle uses
56
49
during 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
58
51
as a Twig extension with Twig. In other words, Twig finds all services tagged
59
52
with ``twig.extension `` and automatically registers them as extensions.
60
53
@@ -359,10 +352,31 @@ To answer this, change the service declaration:
359
352
tags :
360
353
- { name: app.mail_transport }
361
354
362
- versionadded:: 3.3
355
+ .. versionadded :: 3.3
363
356
Support for the compact tag notation in the YAML format was introduced
364
357
in Symfony 3.3.
365
358
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
+
366
380
Notice that you've added a generic ``alias `` key to the tag. To actually
367
381
use this, update the compiler::
368
382
0 commit comments