Description
Symfony version(s) affected
6.2.x
Description
(considering this as a bug because my application breaks after upgrading from 6.1.x)
I have the following interface (slightly simplified):
interface FactoryInterface
{
public static function getSupportedName(): string;
public function create(string $someArgument): CreatedThingInterface
}
So this is basically a simple factory interface. In addition, the static method getSupportedName
is used as index method in conjunction with a tagged iterator, so that all factories get injected as a pair of (logical factory name) + (Symfony service).
From services.php:
->set(SomeClass::class)
->arg('$factories', tagged_iterator('app.factory', defaultIndexMethod: 'getSupportedName'))
Services get automatically tagged by this declaration in services.php:
->instanceof(FactoryInterface::class)
->tag('app.factory')
->lazy()
->tag('proxy', ['interface' => FactoryInterface::class])
As you can see, these factories are also lazy to avoid some initialization work. As by default all my classes are final, I need to add a proxy tag.
The problem is that the generated proxy class doesn't contain that static method, only the non-static method and initializeLazyObject
, so the container compilation fails.
There are workarounds for that problem, but it would be great to have that use case still supported.
Thanks for your efforts!
How to reproduce
- Create an interface that has a static method.
- Create a class that implements this interface and that is final.
- Declare the service for that class and make it lazy + define a proxy tag, stating the interface.
- Inject the service into another service by using a tagged iterator, and specify the static method from the interface as index method.
(details in the description above)
Possible Solution
No response
Additional Context
No response