Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[RFC] Simplify wiring of service locators #29203

Copy link
Copy link
Closed
@zmitic

Description

@zmitic
Issue body actions

@nicolas-grekas on Twitter asked me to create RFC. And when Symfony core member makes a call, you answer that call 😄

Is it possible to have autowiring for Service Locator? Example:

interface CustomizedServiceNameInterface
{
    public static function getName(): string;
}

interface TagCollectionInterface
{
    public static function getTagName(): string;
}

Because components need custom name instead of FQCN, programmer has to implement interface (otherwise, it works as usual FQCN as name):

class HeaderComponent implements CustomizedServiceNameInterface, ComponentInterface
{
    public static function getName(): string
    {
        return 'header';
    }
}

so when I make class that implements TagCollectionInterface:

class MyCollectionOfTaggedServices extends ServiceLocator implements TagCollectionInterface
{
    public static function getTagName(): string
    {
        return ComponentInterface::class;
    }
}

$factories is populated as

array [
  HeaderComponent::getName() => new Reference(HeaderComponent::class),
 // just an example, I know these are callables
];

instead of

array [
  HeaderComponent::class => new Reference(HeaderComponent::class),
];

Right now I have to write a compiler pass:

image

It is pretty messy code, but the thing is that I make array of components where key is read from ComponentInterface::getName() static method. The rest (like $map variable) is irrelevant to Symfony.

Anyway, tell me what you think. This idea will be scraped, I have better idea now (using annotations on controller + kernel.view event), define route tree just like NG and it will be good to go. It will not change the speed but will clean the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DependencyInjectionRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.