Skip to content

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Mar 6, 2017

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

I was looking for a way to save a definition declaration when one uses a FQCN reference:

services:
    my_service:
        arguments: [ '@App\Foo' ]

and not have to declare App\Foo.

One way to achieve this is to couple it with autowiring: if the @App\Foo ref is invalid, AutowirePass can create the target service. This was done in #21859 and further enhanced in #21873 (which adds the requirement that this can happen only in autowired holder definitions.)

Then I wondered: what would one expect with _defaults and _instanceof?
eg

services:
    _instanceof:
        App\FooInterface:
            tags: [ 'foo_tag' ]
    my_service:
        arguments: [ '@App\Foo' ]

Should the App\Foo definition get the foo_tag? Might be a yes, especially if we teach that:

services:
    my_service:
        arguments: [ '@App\Foo' ]

is equivalent to:

services:
    App\Foo : ~
    my_service:
        arguments: [ '@App\Foo' ]

you still follow me?

This is what this PR achieves - and for this, it needs to work at the loader level.

The next step is working with @App\FooInterface: to me, since this cannot be a definition, it has to play well with autowiring, which should be applicable (opt-in-only as usual) to find the correct service implenenting App\FooInterface. OK?

But then, let's says we have class Bar extends Foo {}, and this config:

services:
    _defaults:
        autowire: true
    App\Bar: ~
    my_service:
        arguments: [ '@App\Foo' ]

What should @App\Foo be resolved to? App\Bar as autowiring would do with the corresponding type hint? Or an implicit new App\Foo definition as the previous equivalence principle would lead to?

That's ambiguous to me.

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Mar 6, 2017
@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Mar 6, 2017

Maybe someone would like to resolve these ambiguities?
Meanwhile, I'm closing, keeping here for reference if the topic comes back in the future :)

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.

2 participants