Closed
Description
I was looking at #12521 then #20039. Both deal with lazyness in the event dispatcher.
The issue is having event listeners/dispatchers be instantiated only when actually needed.
ContainerAwareEventDispatcher
partially works around the issue, but in a non generic way (bound to Symfony's DI container and not compatible with private services).
But let's imagine we add a new lazy collection type to our lovely DI component, usable this way:
<service id="foo" class="Foo">
<argument type="iterator">
<argument type="service" id="bar" />
<argument type="service" id="buz" />
<argument key="key" type="service" id="zob" />
</argument>
</service>
Generating this code when compiled (simplified example):
protected function getFooService()
{
return new Foo((function () {
yield $this->get('bar');
yield $this->get('buz');
yield 'key' => $this->get('zob');
})());
}
Then the referenced services would be instantiated only when the generator reaches the corresponding yield statement. This would allow building e.g. a generic lazy event dispatcher.