Skip to content

[TwigBundle] mark TemplateIterator as internal #31828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Bundle/TwigBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

4.4.0
-----

* marked the `TemplateIterator` as `internal`

4.2.0
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 24 additions & 16 deletions src/Symfony/Bundle/TwigBundle/TemplateIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* 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
{
Expand All @@ -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)
{
Expand All @@ -50,40 +52,46 @@ public function getIterator()
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 [];
Expand Down