forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouterDebugCommand.php
More file actions
93 lines (81 loc) · 3.08 KB
/
Copy pathRouterDebugCommand.php
File metadata and controls
93 lines (81 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\RouterDebugCommand.
*/
namespace Drupal\AppConsole\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class RouterDebugCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('router:debug')
->setDescription($this->trans('commands.router.debug.description'))
->addArgument('route-name', InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
$this->trans('commands.router.debug.arguments.route-name'));
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$route_name = $input->getArgument('route-name');
$table = $this->getHelperSet()->get('table');
$table->setlayout($table::LAYOUT_COMPACT);
if ($route_name) {
$this->getRouteByNames($route_name, $output, $table);
} else {
$this->getAllRoutes($output, $table);
}
}
protected function getAllRoutes($output, $table)
{
$rp = $this->getRouteProvider();
$routes = $rp->getAllRoutes();
$table->setHeaders(
[
$this->trans('commands.router.debug.messages.name'),
$this->trans('commands.router.debug.messages.path'),
]);
$table->setlayout($table::LAYOUT_COMPACT);
foreach ($routes as $route_name => $route) {
$table->addRow([$route_name, $route->getPath()]);
}
$table->render($output);
}
protected function getRouteByNames($route_name, $output, $table)
{
$rp = $this->getRouteProvider();
$routes = $rp->getRoutesByNames($route_name);
$table->setHeaders(
[
$this->trans('commands.router.debug.messages.name'),
$this->trans('commands.router.debug.messages.options'),
]
);
$table->setlayout($table::LAYOUT_COMPACT);
foreach ($routes as $name => $route) {
$table->addRow(['<info>' . $name . '</info>']);
$table->addRow([
' <comment>+ ' . $this->trans('commands.router.debug.messages.pattern') . '</comment>',
$route->getPath()
]);
$table->addRow([' <comment>+ ' . $this->trans('commands.router.debug.messages.defaults') . '</comment>']);
$table = $this->addRouteAttributes($route->getDefaults(), $table);
$table->addRow([' <comment>+ ' . $this->trans('commands.router.debug.messages.options') . '</comment>']);
$table = $this->addRouteAttributes($route->getOptions(), $table);
}
$table->render($output);
}
protected function addRouteAttributes($attr, $table)
{
foreach ($attr as $key => $value) {
if (is_array($value)) {
$table = $this->addRouteAttributes($value, $table);
} else {
$table->addRow([' <comment>- </comment>' . $key, $value]);
}
}
return $table;
}
}