Skip to content

[DependencyInjection] Add support for short services configurators syntax #19190

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

Closed
wants to merge 4 commits into from
Closed

[DependencyInjection] Add support for short services configurators syntax #19190

wants to merge 4 commits into from

Conversation

voronkovich
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

This PR adds support for short services configurators syntax in YAML files:

services:
    app.some_service:
        class: ...
        # Common syntax
        configurator: [ '@app.configurator', 'configure' ]
        # Short syntax
        configurator: 'app.configurator:configure'

}

return $callable;
} elseif (is_array($callable)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elseif can be a simple if.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hhamon, You're right, with standalone if code is more readable. I've changed elseif to if. Thanks!

@ro0NL
Copy link
Contributor

ro0NL commented Jun 27, 2016

What about @app.configurator:configure? I would prefer keeping the @ as a service indicator.

@nicolas-grekas
Copy link
Member

As far as I understand correctly, this continues #12008 that missed the "configurator" case?
Could you add a few tests please?

@voronkovich
Copy link
Contributor Author

@ro0NL, I would prefer to use @ too. But it will be a BC break.

@ro0NL
Copy link
Contributor

ro0NL commented Jun 27, 2016

I see. Maybe it's good to mention this is a generic format, ie i thought it was configurator specific at first, but it's also a notation we can use on factories.

The BC is due the fact service id's allow for colons? Im not sure how intuitive this (new) format will be..., what about @app.configurator->configure =/ Anyway is this really better than
['@app.configurator', 'configure'] which is pretty short already imo. We gain 5 chars or so...

@voronkovich
Copy link
Contributor Author

@ro0NL, it is not a new format. It will be a BC break because some people already use short syntax for service factories in their code without using leading @.

@stof
Copy link
Member

stof commented Jun 27, 2016

@voronkovich I don't understand what you mean. app.configurator:configure does not work for a configurator today, because it is not a callable

@stof
Copy link
Member

stof commented Jun 27, 2016

I'm 👍 for making the configurator configuration support the same short syntax than the factory one in Yaml. Being consistent is a good idea

@voronkovich
Copy link
Contributor Author

@nicolas-grekas, do we really need additional tests for this? We already have the tests for services factories: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php#L157

@stof
Copy link
Member

stof commented Jun 27, 2016

@voronkovich if there is a new supported syntax, we need to have a test ensuring that we don't break this syntax by mistake

@voronkovich
Copy link
Contributor Author

@stof, Thanks for the explanation! @nicolas-grekas, I've added the tests and fixed some errors.

@nicolas-grekas
Copy link
Member

👍

@fabpot
Copy link
Member

fabpot commented Jun 29, 2016

Thank you @voronkovich.

@fabpot fabpot closed this Jun 29, 2016
fabpot added a commit that referenced this pull request Jun 29, 2016
…onfigurators syntax (voronkovich)

This PR was squashed before being merged into the 3.2-dev branch (closes #19190).

Discussion
----------

[DependencyInjection] Add support for short services configurators syntax

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

This PR adds support for short services configurators syntax in YAML files:
```yaml
services:
    app.some_service:
        class: ...
        # Common syntax
        configurator: [ '@app.configurator', 'configure' ]
        # Short syntax
        configurator: 'app.configurator:configure'

Commits
-------

da2757f [DependencyInjection] Add support for short services configurators syntax
@voronkovich voronkovich deleted the improve-configurator-syntax branch June 29, 2016 11:30
@fabpot fabpot mentioned this pull request Oct 27, 2016
@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 20, 2019

I propose to deprecate this in #31543

nicolas-grekas added a commit that referenced this pull request May 22, 2019
This PR was merged into the 4.4-dev branch.

Discussion
----------

[DI] deprecate short callables in yaml

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

This deprecates defining factories as `foo:method` instead of `['@foo', 'method']` in yaml.

This is confusing syntax and misses the opportunity to raise an error when one does a typo and uses a single colon instead of two.

This basically reverts #19190

Commits
-------

f8a04fd [DI] deprecate short callables in yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants