8000 Show Twig loader paths on debug:twig command · symfony/symfony@fb340ef · GitHub
[go: up one dir, main page]

Skip to content

Commit fb340ef

Browse files
committed
Show Twig loader paths on debug:twig command
1 parent 042328d commit fb340ef

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Console\Style\SymfonyStyle;
2020
use Twig\Environment;
21+
use Twig\Loader\FilesystemLoader;
2122

2223
/**
2324
* Lists twig functions, filters, globals and tests present in the current project.
@@ -120,6 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
120121
}
121122
}
122123
$data['tests'] = array_keys($data['tests']);
124+
$data['loader_paths'] = $this->getLoaderPaths();
123125
$io->writeln(json_encode($data));
124126

125127
return 0;
@@ -145,9 +147,36 @@ protected function execute(InputInterface $input, OutputInterface $output)
145147
$io->listing($items);
146148
}
147149

150+
$list = [];
151+
foreach ($this->getLoaderPaths() as $namespace => $paths) {
152+
$list = array_merge($list, array_map(function ($path) use ($namespace) {
153+
return $namespace.($namespace ? ': ' : '').$path;
154+
}, $paths));
155+
}
156+
$io->section('Loader Paths');
157+
$io->listing($list);
158+
148159
return 0;
149160
}
150161

162+
private function getLoaderPaths()
163+
{
164+
if (!($loader = $this->twig->getLoader()) instanceof FilesystemLoader) {
165+
return array();
166+
}
167+
168+
$paths = [];
169+
8254 foreach ($loader->getNamespaces() as $namespace) {
170+
if (FilesystemLoader::MAIN_NAMESPACE === $namespace) {
171+
$paths[''] = $loader->getPaths($namespace);
172+
} else {
173+
$paths['@'.$namespace] = $loader->getPaths($namespace);
174+
}
175+
}
176+
177+
return $paths;
178+
}
179+
151180
private function getMetadata($type, $entity)
152181
{
153182
if ($type === 'globals') {

0 commit comments

Comments
 (0)
0