Closed
Description
Description
In our application we rely Symfony's ContainerBuilder::registerAttributeForAutoconfiguration
together with auto wire for a lot of things. I also helped improving it:
But now I have an issue. I have a class that has a private
constructor. It needs to be constructed by calling a static method.
Example:
#[SomeAttribute]
final class SomeService
{
private function __construct() {}
}
I have a compiler pass that tries to work this class by looking for SomeAttribute
:
$container->registerAttributeForAutoconfiguration(
SomeAttribute::class,
static function (ChildDefinition $definition, SomeAttribute $attribute, ReflectionClass $reflector) : void {
// do magic
},
);
I load everything using:
$services->load('App\\', __DIR__ . '/');
Because of this line the class is never loaded because it's not instantiable.
symfony/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
Lines 232 to 234 in 69f46f2
Possible solutions:
- Always run the registered attributes configurators for classes that cannot be instantiated
- Allow an additional option on the
PrototypeConfigurator
to indicate you want to always load attributes - Change the condition above:
- if ($r->isInstantiable() || $r->isInterface()) { - $classes[$class] = null; - } + $classes[$class] = null;
/cc @nicolas-grekas since we worked in this area together in #42039 do you have ideas?
Example
No response