|
5 | 5 | How to Work with Service Tags
|
6 | 6 | =============================
|
7 | 7 |
|
8 |
| -In the same way that a blog post on the web might be tagged with things such |
9 |
| -as "Symfony" or "PHP", services configured in your container can also be |
10 |
| -tagged. In the service container, a tag implies that the service is meant |
11 |
| -to be used for a specific purpose. Take the following example: |
| 8 | +Some container services require to be registered or used in some special way. |
| 9 | +Consider for example the :doc:`Twig extensions </templating/twig_extension>`: |
| 10 | +they are PHP classes that must be added to the main Twig object before using |
| 11 | +them. If you define those exensions as regular Symfony services, Twig will |
| 12 | +ignore them and an exception will be thrown when using them in templates. |
| 13 | + |
| 14 | +**Service tags** are a way to tell Symfony or other third-party bundles that |
| 15 | +your service should be registered in some special way. Take the following |
| 16 | +example: |
12 | 17 |
|
13 | 18 | .. configuration-block::
|
14 | 19 |
|
@@ -51,14 +56,10 @@ to be used for a specific purpose. Take the following example:
|
51 | 56 | ->setPublic(false)
|
52 | 57 | ->addTag('twig.extension');
|
53 | 58 |
|
54 |
| -The ``twig.extension`` tag is a special tag that the TwigBundle uses |
55 |
| -during configuration. By giving the service this ``twig.extension`` tag, |
56 |
| -the bundle knows that the ``app.twig_extension`` service should be registered |
57 |
| -as a Twig extension with Twig. In other words, Twig finds all services tagged |
58 |
| -with ``twig.extension`` and automatically registers them as extensions. |
59 |
| - |
60 |
| -Tags, then, are a way to tell Symfony or other third-party bundles that |
61 |
| -your service should be registered or used in some special way by the bundle. |
| 59 | +Services tagged with the ``twig.extension`` tag are collected during the |
| 60 | +initialization of TwigBundle to enable them as Twig extensions. In this example, |
| 61 | +that's why Symfony knows that the ``app.twig_extension`` service should be |
| 62 | +registered as a Twig extension. |
62 | 63 |
|
63 | 64 | For a list of all the tags available in the core Symfony Framework, check
|
64 | 65 | out :doc:`/reference/dic_tags`. Each of these has a different effect on your
|
|
0 commit comments