Skip to content

[DI] Anonymous services support for YamlFileLoader #16328

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

Conversation

prgTW
Copy link

@prgTW prgTW commented Oct 23, 2015

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

Example:

services:
    first:
        class: FooClass
        arguments: [ { type: service, class: BazClass } ]
    second:
        class: FooClass
        arguments:
            - type: service
              class: BazClass
            - type: service
              class: BarClass

@prgTW prgTW force-pushed the feat/di/yaml-loader-anonymous-services branch 2 times, most recently from c90fa7f to 4f282e8 Compare October 23, 2015 23:25
@prgTW prgTW force-pushed the feat/di/yaml-loader-anonymous-services branch from 4f282e8 to 455375f Compare October 23, 2015 23:26
@SongoQ
Copy link
Contributor

SongoQ commented Oct 24, 2015

👍

@sstok
Copy link
Contributor

sstok commented Oct 24, 2015

This is a BC break as an argument can also an array, and there is no way to determine if it is in fact an array with the key 'type' or a service definition.

@prgTW
Copy link
Author

prgTW commented Oct 24, 2015

You re right, it's a BC break. IMHO I'm introducing a convention here which is similar to @/@@/@?/@= notation. I wanted to do it as similar as it could be comparing with XML format and thus having steep learning curve

@linaori
Copy link
Contributor

linaori commented Oct 24, 2015

I can understand the need for this, but I don't think this current implementation is the correct one.

Can you add some more information about what you're changing and why you're changing it? It will help people to understand the PR a lot better.

@stof
Copy link
Member

stof commented Oct 25, 2015

-1 on the current implementation. Such BC break is impossible. It is far too big (imagine the case where you inject an array in your service without knowing its content as it comes from the user config)

@xabbuh
Copy link
Member

xabbuh commented Oct 25, 2015

Status: Needs work

@fabpot
Copy link
Member

fabpot commented Oct 25, 2015

Closing as it cannot be merged and I don't see a huge benefit in being able to create anonymous services in userland. For core and bundles, it's recommended to use XML anyway where anonymous services are supported.

@fabpot fabpot closed this Oct 25, 2015
@prgTW prgTW deleted the feat/di/yaml-loader-anonymous-services branch October 25, 2015 18:57
@GuilhemN
Copy link
Contributor

I opened #21970 which allows anonymous services in yaml using the !service tag.

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
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.

9 participants