Closed
Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | no |
Symfony version | 4.1 |
The use case is supporting interface like the EventSubscriberInterface one, where the static method is called at compile-time to configure the container. In such case, changing the implementation of the static method must invalidate the container.
Currently, we have 2 choices for that:
- invalidate the container any time the class definition changes, by using
$container->addObjectResource
. This is working, but it invalidates it much too often, as changes might be in other methods instead. This leads to poor DX (having to wait for the cache being rebuilt) when the class is likely to be edited for another place. - [Config] Handle Service/EventSubscriberInterface in ReflectionClassResource #25976 is hardcoding special support for EventSubscriberInterface and ServiceSubscriberInterface (which are the 2 interfaces using this pattern in the core) in the existing ReflectionClassResource, converting the usage to
$container->getReflectionClass
in related compiler passes. This has 2 drawbacks:- it is not reusable for external bundles having a similar need for their own interface (forcing them to go for the first option with bad DX)
- it applies this invalidation to these classes even if they were not registered in the corresponding compiler passes (and so these interfaces were irrelevant for them) but they were still handled through
$container->getReflectionClass
in a different place (I recognize this is a bit of an edge case)
The idea here would be to provide a new kind of resource implementing the invalidation for this case, separate from the ReflectionClassResource. This resource should be configurable for different interfaces.
The case of the EventSubscriberInterface could then be migrated to using this new resource, avoiding the hardcoded handling of it in ReflectionClassResource.