Skip to content
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

Zero-Config: Resolve class by service name #21667

Closed
ScreamingDev opened this issue Feb 18, 2017 · 4 comments
Closed

Zero-Config: Resolve class by service name #21667

ScreamingDev opened this issue Feb 18, 2017 · 4 comments
Labels
DependencyInjection Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@ScreamingDev
Copy link

ScreamingDev commented Feb 18, 2017

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.3.0

Just have heard about the Zero-Config activities so I like to give in some idea. I tried to implement it but it seems a bit bigger so I like to ask before.

Service configuration without passing class

Imagine this services.yml defining a custom service:

services:
  foo.bar.baz_qux:
    arguments: [ 1, 2, 3 ]

What's clearly missing is the class: argument.
With the correct service name the class could be resolved.
As I experienced this occurs quite often for ...

  • Repositories
  • CommandHandler
  • Controller / or Action-Classes

Because they got that singleton touch.

Resolving class name

The class for foo.bar.baz_qux should be looked up like this:

  • Check for \FooBundle\Bar\BazQux class
    • Every dot became a backslash
    • Underscore separates words (ucwords())
    • The other rules are (hopefully) obvious.
  • Check for \FooBundle\Bar\Baz_Qux class
  • Check for \Foo\Bar\BazQux class
  • Check for \Foo\Bar\Baz_Qux class
  • Throw exception about missing or unresolvable class
@javiereguiluz javiereguiluz added DependencyInjection Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Feb 19, 2017
@dosten
Copy link
Contributor

dosten commented Feb 19, 2017

👎

You can use:

services:
  FooBundle\Bar\BazQux:
    arguments: [ 1, 2, 3 ]

@xabbuh
Copy link
Member

xabbuh commented Feb 20, 2017

👎 for me as well. If you want to omit the class attribute, you can use the service id for it. That should be enough and less confusing than adding another convention to achieve this.

@javiereguiluz
Copy link
Member

@sourcerer-mike thanks for making a proposal to improve Symfony. However, as you can see the feedback from the community is not very positive, so I must close this as "won't fix".

Although this time your proposal didn't make it, please keep making proposals and asking for new features in the future. That's what makes us advance! Thanks.

@nicolas-grekas
Copy link
Member

@sourcerer-mike just in case you missed it: http://symfony.com/blog/new-in-symfony-3-3-optional-class-for-named-services

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

No branches or pull requests

5 participants