minor #31828 [TwigBundle] mark TemplateIterator as internal (Tobion)
This PR was merged into the 4.4 branch.
Discussion
----------
[TwigBundle] mark TemplateIterator as internal
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
This class is an implementation detail and should not be relied on as an extension point. This is also why TemplateCacheWarmer does not typhint this class but iterable. By making it internal we can remove the rootDir argument in #31823
Commits
-------
9b46c17911
[TwigBundle] mark TemplateIterator as internal
This commit is contained in:
commit
957a0b82cb
@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
4.4.0
|
||||
-----
|
||||
|
||||
* marked the `TemplateIterator` as `internal`
|
||||
|
||||
4.2.0
|
||||
-----
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 [];
|
||||
|
Reference in New Issue
Block a user