Skip to content

Commit dc9ac9b

Browse files
committed
feature #7860 Use the short Yaml syntax for service definition (GuilhemN)
This PR was squashed before being merged into the master branch (closes #7860). Discussion ---------- Use the short Yaml syntax for service definition ~Fix #7441 Commits ------- 4216289 Use the short Yaml syntax for service definition
2 parents ca9f215 + 4216289 commit dc9ac9b

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

service_container/tags.rst

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
5649
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
5851
as a Twig extension with Twig. In other words, Twig finds all services tagged
5952
with ``twig.extension`` and automatically registers them as extensions.
6053

@@ -359,7 +352,7 @@ 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

0 commit comments

Comments
 (0)