-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Use the short Yaml syntax for service definition #7860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,7 @@ to be used for a specific purpose. Take the following example: | |
|
||
# app/config/services.yml | ||
services: | ||
app.twig_extension: | ||
class: AppBundle\Twig\AppExtension | ||
AppBundle\Twig\AppExtension: | ||
public: false | ||
tags: [twig.extension] | ||
|
||
|
@@ -31,11 +30,7 @@ to be used for a specific purpose. Take the following example: | |
http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service | ||
id="app.twig_extension" | ||
class="AppBundle\Twig\AppExtension" | ||
public="false"> | ||
|
||
<service id="AppBundle\Twig\AppExtension" public="false"> | ||
<tag name="twig.extension" /> | ||
</service> | ||
</services> | ||
|
@@ -45,16 +40,14 @@ to be used for a specific purpose. Take the following example: | |
|
||
// app/config/services.php | ||
use AppBundle\Twig\AppExtension; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
$definition = new Definition(AppExtension::class); | ||
$definition->setPublic(false); | ||
$definition->addTag('twig.extension'); | ||
$container->setDefinition('app.twig_extension', $definition); | ||
$container->register(AppExtension::class) | ||
->setPublic(false) | ||
->addTag('twig.extension'); | ||
|
||
The ``twig.extension`` tag is a special tag that the TwigBundle uses | ||
during configuration. By giving the service this ``twig.extension`` tag, | ||
the bundle knows that the ``app.twig_extension`` service should be registered | ||
the bundle knows that the ``AppExtension::class`` service should be registered | ||
as a Twig extension with Twig. In other words, Twig finds all services tagged | ||
with ``twig.extension`` and automatically registers them as extensions. | ||
|
||
|
@@ -359,10 +352,31 @@ To answer this, change the service declaration: | |
tags: | ||
- { name: app.mail_transport } | ||
|
||
versionadded:: 3.3 | ||
.. versionadded:: 3.3 | ||
Support for the compact tag notation in the YAML format was introduced | ||
in Symfony 3.3. | ||
|
||
.. tip:: | ||
|
||
In YAML format, you may define a service with a simple array of tags as long | ||
as you don't need additional attributes. The following definitions are | ||
equivalent. | ||
|
||
.. code-block:: yaml | ||
|
||
services: | ||
|
||
# Compact syntax | ||
AppBundle\Twig\AppExtension: [twig.extension] | ||
|
||
# Verbose syntax | ||
AppBundle\Twig\AppExtension: | ||
tags: [twig.extension] | ||
|
||
.. versionadded:: 3.3 | ||
Support for the short syntax for service definition in the YAML format | ||
was introduced in Symfony 3.3. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree I didn't realize I added it in .. tip::
In YAML format, you may define a service with a simple array of tags as long
as you don't need additional attributes. The following definitions are
equivalent.
.. code-block:: yaml
services:
# Compact syntax
AppBundle\Twig\AppExtension: [twig.extension]
# Verbose syntax
AppBundle\Twig\AppExtension:
tags: [twig.extension]
.. versionadded:: 3.3
Support for the short syntax for service definition in the YAML format
was introduced in Symfony 3.3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually rethinking about it, does it make sense? We don't talk about tags in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we already have a place where we explain the difference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, it was requested by #7441. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, not sure if we really need this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this be confusing for people who try to use it in lower versions because of our exemples using this syntax ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we talk about different things? Do you mean the |
||
|
||
Notice that you've added a generic ``alias`` key to the tag. To actually | ||
use this, update the compiler:: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hesitated to use
_defaults
here to be able to remove this line and use the short syntax, wdyt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say, let's not add the "defaults" until we decide what to do with that new option.