8000 [TwigBridge] Show Twig's loader paths on debug:twig command by yceruto · Pull Request #24064 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge] Show Twig's loader paths on debug:twig command #24064

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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Show Twig loader paths on debug:twig command
  • Loading branch information
yceruto committed Sep 1, 2017
commit 40a4bb389b1ffbf3a34c8ccd2712774627b9d0a9
29 changes: 29 additions & 0 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

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

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

$list = array();
foreach ($this->getLoaderPaths() as $namespace => $paths) {
$list = array_merge($list, array_map(function ($path) use ($namespace) {
return $namespace.($namespace ? ': ' : '').$path;
}, $paths));
}
$io->section('Loader Paths');
$io->listing($list);

return 0;
}

private function getLoaderPaths()
{
if (!($loader = $this->twig->getLoader()) instanceof FilesystemLoader) {
return array();
}

$paths = array();
foreach ($loader->getNamespaces() as $namespace) {
if (FilesystemLoader::MAIN_NAMESPACE === $namespace) {
$paths[''] = $loader->getPaths($namespace);
} else {
$paths['@'.$namespace] = $loader->getPaths($namespace);
}
}

return $paths;
}

private function getMetadata($type, $entity)
{
if ($type === 'globals') {
Expand Down
0