diff --git a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md index 1be455e4e8..d25f9aae79 100644 --- a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.4.0 +----- + + * marked the `TemplateIterator` as `internal` + 4.2.0 ----- diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php index cb9af8a462..6150e5c1ca 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php @@ -28,7 +28,7 @@ class TemplateCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInte private $twig; private $iterator; - public function __construct(ContainerInterface $container, \Traversable $iterator) + public function __construct(ContainerInterface $container, iterable $iterator) { // As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected. $this->container = $container; diff --git a/src/Symfony/Bundle/TwigBundle/TemplateIterator.php b/src/Symfony/Bundle/TwigBundle/TemplateIterator.php index 17aca046f8..3ad83ef818 100644 --- a/src/Symfony/Bundle/TwigBundle/TemplateIterator.php +++ b/src/Symfony/Bundle/TwigBundle/TemplateIterator.php @@ -18,6 +18,8 @@ use Symfony\Component\HttpKernel\KernelInterface; * Iterator for all templates in bundles and in the application Resources directory. * * @author Fabien Potencier + * + * @internal since Symfony 4.4 */ class TemplateIterator implements \IteratorAggregate { @@ -31,7 +33,7 @@ class TemplateIterator implements \IteratorAggregate * @param KernelInterface $kernel A KernelInterface instance * @param string $rootDir The directory where global templates can be stored * @param array $paths Additional Twig paths to warm - * @param string $defaultPath The directory where global templates can be stored + * @param string|null $defaultPath The directory where global templates can be stored */ public function __construct(KernelInterface $kernel, string $rootDir, array $paths = [], string $defaultPath = null) { @@ -50,40 +52,46 @@ class TemplateIterator implements \IteratorAggregate return $this->templates; } - $this->templates = array_merge( - $this->findTemplatesInDirectory($this->rootDir.'/Resources/views'), - $this->findTemplatesInDirectory($this->defaultPath, null, ['bundles']) - ); + $templates = $this->findTemplatesInDirectory($this->rootDir.'/Resources/views'); + + if (null !== $this->defaultPath) { + $templates = array_merge( + $templates, + $this->findTemplatesInDirectory($this->defaultPath, null, ['bundles']) + ); + } foreach ($this->kernel->getBundles() as $bundle) { $name = $bundle->getName(); if ('Bundle' === substr($name, -6)) { $name = substr($name, 0, -6); } - $this->templates = array_merge( - $this->templates, + $templates = array_merge( + $templates, $this->findTemplatesInDirectory($bundle->getPath().'/Resources/views', $name), - $this->findTemplatesInDirectory($this->rootDir.'/Resources/'.$bundle->getName().'/views', $name), - $this->findTemplatesInDirectory($this->defaultPath.'/bundles/'.$bundle->getName(), $name) + $this->findTemplatesInDirectory($this->rootDir.'/Resources/'.$bundle->getName().'/views', $name) ); + if (null !== $this->defaultPath) { + $templates = array_merge( + $templates, + $this->findTemplatesInDirectory($this->defaultPath.'/bundles/'.$bundle->getName(), $name) + ); + } } foreach ($this->paths as $dir => $namespace) { - $this->templates = array_merge($this->templates, $this->findTemplatesInDirectory($dir, $namespace)); + $templates = array_merge($templates, $this->findTemplatesInDirectory($dir, $namespace)); } - return $this->templates = new \ArrayIterator(array_unique($this->templates)); + return $this->templates = new \ArrayIterator(array_unique($templates)); } /** * Find templates in the given directory. * - * @param string $dir The directory where to look for templates - * @param string|null $namespace The template namespace - * - * @return array + * @return string[] */ - private function findTemplatesInDirectory($dir, $namespace = null, array $excludeDirs = []) + private function findTemplatesInDirectory(string $dir, string $namespace = null, array $excludeDirs = []): array { if (!is_dir($dir)) { return [];