8000 Show short path (from project root) and display table · symfony/symfony@7cd2b29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cd2b29

Browse files
committed
Show short path (from project root) and display table
1 parent 40a4bb3 commit 7cd2b29

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Twig\Command;
1313

1414
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Helper\TableSeparator;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Input\InputInterface;
@@ -30,11 +31,13 @@ class DebugCommand extends Command
3031
protected static $defaultName = 'debug:twig';
3132

3233
private $twig;
34+
private $projectDir;
3335

3436
/**
3537
* @param Environment $twig
38+
* @param string|null $projectDir
3639
*/
37-
public function __construct($twig = null)
40+
public function __construct($twig = null, $projectDir = null)
3841
{
3942
if (!$twig instanceof Environment) {
4043
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
@@ -47,6 +50,7 @@ public function __construct($twig = null)
4750
parent::__construct();
4851

4952
$this->twig = $twig;
53+
$this->projectDir = $projectDir;
5054
}
5155

5256
public function setTwigEnvironment(Environment $twig)
@@ -147,14 +151,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
147151
$io->listing($items);
148152
}
149153

150-
$list = array();
154+
$rows = array();
151155
foreach ($this->getLoaderPaths() as $namespace => $paths) {
152-
$list = array_merge($list, array_map(function ($path) use ($namespace) {
153-
return $namespace.($namespace ? ': ' : '').$path;
154-
}, $paths));
156+
foreach ($paths as $path) {
157+
$rows[] = array($namespace, '* '.$path);
158+
$namespace = '';
159+
}
160+
$rows[] = new TableSeparator();
155161
}
162+
array_pop($rows);
156163
$io->section('Loader Paths');
157-
$io->listing($list);
164+
$io->table(array('Namespace', 'Paths'), $rows);
158165

159166
return 0;
160167
}
@@ -165,16 +172,26 @@ private function getLoaderPaths()
165172
return array();
166173
}
167174

168-
$paths = array();
175+
$loaderPaths = array();
169176
foreach ($loader->getNamespaces() as $namespace) {
177+
$paths = array_map(function ($path) use ($namespace) {
178+
if (null !== $this->projectDir && 0 === strpos($path, $this->projectDir)) {
179+
$path = ltrim(substr($path, strlen($this->projectDir)), DIRECTORY_SEPARATOR);
180+
}
181+
182+
return $path;
183+
}, $loader->getPaths($namespace));
184+
170185
if (FilesystemLoader::MAIN_NAMESPACE === $namespace) {
171-
$paths[''] = $loader->getPaths($namespace);
186+
$namespace = '(None)';
172187
} else {
173-
$paths['@'.$namespace] = $loader->getPaths($namespace);
188+
$namespace = '@'.$namespace;
174189
}
190+
191+
$loaderPaths[$namespace] = $paths;
175192
}
176193

177-
return $paths;
194+
return $loaderPaths;
178195
}
179196

180197
private function getMetadata($type, $entity)

src/Symfony/Bundle/TwigBundle/Resources/config/console.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<service id="Symfony\Bridge\Twig\Command\DebugCommand">
1111
<argument type="service" id="twig" />
12+
<argument>%kernel.project_dir%</argument>
1213
<tag name="console.command" command="debug:twig" />
1314
</service>
1415

0 commit comments

Comments
 (0)
0