1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Eccube\Command; |
25
|
|
|
|
26
|
|
|
use Symfony\Component\Console\Helper\Table; |
27
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
28
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
29
|
|
|
use Symfony\Component\Console\Input\InputOption; |
30
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
31
|
|
|
use Symfony\Component\Routing\Route; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
class RouterCommand extends \Knp\Command\Command |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
protected function configure() |
37
|
|
|
{ |
38
|
|
|
$this |
39
|
|
|
->setName('router:debug') |
40
|
|
|
->setDefinition( |
41
|
|
|
[ |
42
|
|
|
new InputArgument('name', InputArgument::OPTIONAL, 'A route name'), |
43
|
|
|
] |
44
|
|
|
) |
45
|
|
|
->addOption( |
46
|
|
|
'sort', |
47
|
|
|
null, |
48
|
|
|
InputOption::VALUE_OPTIONAL, |
49
|
|
|
'[null/ASC/DESC]. If argument orderby set, Default is ASC.' |
50
|
|
|
) |
51
|
|
|
->addOption( |
52
|
|
|
'orderby', |
53
|
|
|
null, |
54
|
|
|
InputOption::VALUE_OPTIONAL, |
55
|
|
|
'[null/name/path]. If argument sort set, Default is name.' |
56
|
|
|
) |
57
|
|
|
->setDescription('Displays current routes for an application') |
58
|
|
|
->setHelp( |
59
|
|
|
<<<EOF |
60
|
|
|
The <info>%command.name%</info> displays the configured routes: |
61
|
|
|
<info>php %command.full_name%</info> |
62
|
|
|
EOF |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
67
|
|
|
{ |
68
|
|
|
$app = $this->getSilexApplication(); |
69
|
|
|
|
70
|
|
|
$filter = $input->getArgument('name'); |
71
|
|
|
$sort = $input->getOption('sort'); |
72
|
|
|
$orderby = $input->getOption('orderby'); |
73
|
|
|
|
74
|
|
|
$table = new Table($output); |
75
|
|
|
$table->setHeaders(['Name', 'Path', 'Method', 'Controller']); |
76
|
|
|
|
77
|
|
|
$routes = $app['routes']->all(); |
78
|
|
|
|
79
|
|
|
// 引数で並び替える。 |
80
|
|
|
if (!empty($sort)) { |
81
|
|
|
$orderby = !empty($orderby) ? $orderby : "name"; |
82
|
|
|
} |
83
|
|
|
if (!empty($orderby)) { |
84
|
|
|
$sort = !empty($sort) ? $sort : "ASC"; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if (strtoupper($orderby) === "NAME") { |
88
|
|
|
if (strtoupper($sort) === "DESC") { |
89
|
|
|
krsort($routes); |
90
|
|
|
} else { |
91
|
|
|
ksort($routes); |
92
|
|
|
} |
93
|
|
|
} else { |
94
|
|
|
if (strtoupper($orderby) === "PATH") { |
95
|
|
|
uasort( |
96
|
|
|
$routes, |
97
|
|
|
function ($a, $b) { |
98
|
|
|
return strcmp($a->getPath(), $b->getPath()); |
99
|
|
|
} |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
// filterで指定した条件以外を除外 |
105
|
|
|
foreach ($routes as $name => $route) { |
106
|
|
|
if (!empty($filter) && !preg_match("/$filter/", $name)) { |
107
|
|
|
unset($routes[$name]); |
108
|
|
|
continue; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
foreach ($routes as $name => $route) { |
113
|
|
|
/** @var Route $route */ |
114
|
|
|
$path = $route->getPath(); |
115
|
|
|
$methods = $route->getMethods(); |
116
|
|
|
$methods = empty($methods) |
117
|
|
|
? 'ANY' |
118
|
|
|
: implode(',', $methods); |
119
|
|
|
$controller = $route->getDefault('_controller'); |
120
|
|
|
|
121
|
|
|
$table->addRow( |
122
|
|
|
[ |
123
|
|
|
$name, |
124
|
|
|
$path, |
125
|
|
|
$methods, |
126
|
|
|
$controller, |
127
|
|
|
] |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$table->render($output); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|