Description
@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:
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.