Closed Biont closed 4 years ago
This is definitely a bug. To fix this bug, the delegating container must have a reference to the caching container. However, it cannot obtain that reference, because the caching container cannot exist before the delegating one, since it can only receive the inner container at construction time.
This is ultimately the chicken-egg problem that I have already encountered before with lookup delegation: the top-most container requires a reference to the inner container to lookup, and the inner container requires a reference to the top-most container to pass it down to service definitions.
Create a 3rd container with a very explicit setter, e.g. ProxyContainer::setContainer(ContainerInterface $inner)
. This proxy container will do nothing but forward calls to its inner container. The advantage is that you can use the setter to set the inner container at any time after creation of the proxy. In this particular case, you would use it like so:
$proxy = new ProxyContainer();
$container = new CachingContainer(new DelegatingContainer(new ServiceProvider($factories, []), $proxy));
$proxy->setContainer($container);
Thank you for the quick response. This looks good
The
CachingContainer
decorates a child container. So if an entry is not yet cached, it is fetched from the child. But that means that any uncached entry is not able to pull cached dependencies, because theCachingContainer
is not passed down.