Skip to content

[DependencyInjection] Support anonymous services in Yaml #21970

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
Mar 14, 2017

Conversation

GuilhemN
Copy link
Contributor

@GuilhemN GuilhemN commented Mar 10, 2017

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

This PR allows creating anonymous services in yaml using the !service tag as proposed by @nicolas-grekas:

services:
    _instanceof:
        FooInterface:
            arguments:
                - !service
                    class: Bar
                    autowire: true

    Foo:
        factory: [ !service { class: Quz }, 'constructFoo' ]

Anonymous services are forbidden in parameters as in xml.
Defaults and instanceof conditionals aren't applied on anonymous services, as in xml too.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍

Defaults and instanceof conditionals aren't applied on anonymous services, as in xml too.

Just wondering about this catch. Does anyone have an opinion on this? (for another PR thought)


throw new InvalidArgumentException(sprintf('Unsupported tag "!%s".', $value->getTag()));
}

if (is_array($value)) {
$value = array_map(array($this, 'resolveServices'), $value);
foreach ($value as &$v) {
Copy link
Member

Choose a reason for hiding this comment

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

would be better to get rid of the reference to me

@@ -696,12 +701,39 @@ private function resolveServices($value)

return new ClosureProxyArgument($argument[0], $argument[1], $invalidBehavior);
}
// Anonymous service
Copy link
Member

Choose a reason for hiding this comment

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

not sure this comment provides anything

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Mar 14, 2017

Defaults and instanceof conditionals aren't applied on anonymous services, as in xml too.

Thinking a bit more about this, my opinion on it is that it's a bug that should be fixed in XmlFileLoader also.

@nicolas-grekas
Copy link
Member

good to merge as is to me, my previous comments are for another PR

@fabpot
Copy link
Member

fabpot commented Mar 14, 2017

Thank you @GuilhemN.

@fabpot fabpot merged commit 9b71385 into symfony:master Mar 14, 2017
fabpot added a commit that referenced this pull request Mar 14, 2017
…ml (GuilhemN)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DependencyInjection] Support anonymous services in Yaml

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #16328
| License       | MIT
| Doc PR        |

This PR allows creating anonymous services in yaml using the `!service` tag as proposed by @nicolas-grekas:
```yml
services:
    _instanceof:
        FooInterface:
            arguments:
                - !service
                    class: Bar
                    autowire: true

    Foo:
        factory: [ !service { class: Quz }, 'constructFoo' ]
```

Anonymous services are forbidden in parameters as in xml.
Defaults and instanceof conditionals aren't applied on anonymous services, as in xml too.

Commits
-------

9b71385 [DependencyInjection] Support anonymous services in Yaml
@GuilhemN GuilhemN deleted the INLINESERVICE branch March 14, 2017 21:40
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants