[TwigBundle] mark TemplateIterator as internal

so we can remove the rootDir argument in 5.0
This commit is contained in:
Tobias Schultze 2019-06-03 18:55:55 +02:00
parent 693cbff647
commit 9b46c17911
3 changed files with 30 additions and 17 deletions

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
4.4.0
-----
* marked the `TemplateIterator` as `internal`
4.2.0
-----

View File

@ -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;

View File

@ -18,6 +18,8 @@ use Symfony\Component\HttpKernel\KernelInterface;
* Iterator for all templates in bundles and in the application Resources directory.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @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 [];