mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -18,72 +18,64 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
||||
* Iterator for all templates in bundles and in the application Resources directory.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @implements \IteratorAggregate<int, string>
|
||||
*/
|
||||
class TemplateIterator implements \IteratorAggregate
|
||||
{
|
||||
private $kernel;
|
||||
private $rootDir;
|
||||
private $templates;
|
||||
private $paths;
|
||||
private $defaultPath;
|
||||
|
||||
/**
|
||||
* @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 array $paths Additional Twig paths to warm
|
||||
* @param string|null $defaultPath The directory where global templates can be stored
|
||||
*/
|
||||
public function __construct(KernelInterface $kernel, $rootDir, array $paths = [], $defaultPath = null)
|
||||
public function __construct(KernelInterface $kernel, array $paths = [], string $defaultPath = null)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->rootDir = $rootDir;
|
||||
$this->paths = $paths;
|
||||
$this->defaultPath = $defaultPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIterator()
|
||||
public function getIterator(): \Traversable
|
||||
{
|
||||
if (null !== $this->templates) {
|
||||
return $this->templates;
|
||||
}
|
||||
|
||||
$this->templates = array_merge(
|
||||
$this->findTemplatesInDirectory($this->rootDir.'/Resources/views'),
|
||||
$this->findTemplatesInDirectory($this->defaultPath, null, ['bundles'])
|
||||
);
|
||||
$templates = null !== $this->defaultPath ? [$this->findTemplatesInDirectory($this->defaultPath, null, ['bundles'])] : [];
|
||||
|
||||
foreach ($this->kernel->getBundles() as $bundle) {
|
||||
$name = $bundle->getName();
|
||||
if ('Bundle' === substr($name, -6)) {
|
||||
if (str_ends_with($name, 'Bundle')) {
|
||||
$name = substr($name, 0, -6);
|
||||
}
|
||||
|
||||
$this->templates = array_merge(
|
||||
$this->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)
|
||||
);
|
||||
$bundleTemplatesDir = is_dir($bundle->getPath().'/Resources/views') ? $bundle->getPath().'/Resources/views' : $bundle->getPath().'/templates';
|
||||
|
||||
$templates[] = $this->findTemplatesInDirectory($bundleTemplatesDir, $name);
|
||||
if (null !== $this->defaultPath) {
|
||||
$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[] = $this->findTemplatesInDirectory($dir, $namespace);
|
||||
}
|
||||
|
||||
return $this->templates = new \ArrayIterator(array_unique($this->templates));
|
||||
return $this->templates = new \ArrayIterator(array_unique(array_merge([], ...$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