Closed TheCelavi closed 3 months ago
ah indeed. Supporting lazy-loaded iterators would require making the ChainLoader configuration immutable instead of having this addLoader
. So let's forget it...
There is also this method which can be used to preserve lazy loading:
public function addLoader(LoaderInterface $loader): void
{
$existing = $this->loaders;
$this->loaders = static function () use ($existing, $loader): \Generator {
yield from $existing;
yield $loader;
};
$this->hasSourceCache = [];
}
I don't think that it would have much of the performance impact when adding 5-10 loaders (hardly real-world scenario, people usually use 1-2 loaders and that is it).
Are you more interested in this method? @stof
We could deprecate addLoader()
in 3.x
and introduce lazy loading in Twig 4.
I have updated PR with modification which will support preserving lazy loading of loaders with addLoaders()
method.
Thank you @TheCelavi.
Closes #4200