Skip to content

[DependencyInjection] Added Yaml syntax shortcut for name-only tags #20651

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

Merged
merged 1 commit into from
Dec 13, 2016

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Nov 27, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR todo

This PR adds a little shorcut for tags without any attributes. There are increasingly more name-only tags in Symfony and having to do { name: twig.extension } for these seems way too verbose to me.

Before

services:
    app.twig_extension:
        class: AppBundle\Twig\AppExtension
        tags:
            - { name: twig.extension }

After

services:
    app.twig_extension:
        class: AppBundle\Twig\AppExtension
        tags: [twig.extension]
        # or
        #    - twig.extension

This of course means we introduce a new format to achieve the same goal. I believe this isn't a big problem as the decision is distinctive and simple: If you configure tag attributes, use the long format, otherwise use the short format.

Backwards compatibility

In this PR, an exception was removed to allow this new shortcut format. The BC promise doesn't cover exceptions and I think removing the exception here should cause anything to break:

  • Applications shouldn't rely on exceptions
  • If code was triggering this exception before, it would not cause any behaviour change after this PR: The service just retrieves an unused tag, which is simply ignored by the container.

@wouterj
Copy link
Member Author

wouterj commented Nov 27, 2016

I just filled in the PR table incorrectly, someone please remove the BC break label 😃

@javiereguiluz javiereguiluz added the DX DX = Developer eXperience (anything that improves the experience of using Symfony) label Nov 27, 2016
@ogizanagi
Copy link
Contributor

Great 👍

Status: Reviewed

@xabbuh
Copy link
Member

xabbuh commented Nov 28, 2016

👍

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@fabpot
Copy link
Member

fabpot commented Dec 13, 2016

Thank you @wouterj.

@fabpot fabpot merged commit 7fa8c8a into symfony:master Dec 13, 2016
fabpot added a commit that referenced this pull request Dec 13, 2016
…ame-only tags (wouterj)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DependencyInjection] Added Yaml syntax shortcut for name-only tags

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | todo

This PR adds a little shorcut for tags without any attributes. There are increasingly more name-only tags in Symfony and having to do `{ name: twig.extension }` for these seems way too verbose to me.

**Before**
```yaml
services:
    app.twig_extension:
        class: AppBundle\Twig\AppExtension
        tags:
            - { name: twig.extension }
```

**After**
```yaml
services:
    app.twig_extension:
        class: AppBundle\Twig\AppExtension
        tags: [twig.extension]
        # or
        #    - twig.extension
```

This of course means we introduce a new format to achieve the same goal. I believe this isn't a big problem as the decision is distinctive and simple: If you configure tag attributes, use the long format, otherwise use the short format.

Backwards compatibility
---

In this PR, an exception was removed to allow this new shortcut format. The BC promise doesn't cover exceptions and I think removing the exception here should cause anything to break:

 * Applications shouldn't rely on exceptions
 * If code was triggering this exception before, it would not cause any behaviour change after this PR: The service just retrieves an unused tag, which is simply ignored by the container.

Commits
-------

7fa8c8a Added Yaml syntax shortcut for name-only tags
@wouterj wouterj deleted the di/yaml-tag-shortcut branch December 13, 2016 09:19
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants