|
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\Application; |
|
27
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
28
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
29
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
30
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
31
|
|
|
use Symfony\Component\Console\Helper\TableHelper; |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
class RouterCommand extends \Knp\Command\Command |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
protected $app; |
|
38
|
|
|
|
|
39
|
|
|
public function __construct(\Eccube\Application $app, $name = null) { |
|
|
|
|
|
|
40
|
|
|
parent::__construct($name); |
|
41
|
|
|
$this->app = $app; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function configure() { |
|
45
|
|
|
$this |
|
46
|
|
|
->setName('router:debug') |
|
47
|
|
|
->setDefinition(array( |
|
48
|
|
|
new InputArgument('name', InputArgument::OPTIONAL, 'A route name'), |
|
49
|
|
|
)) |
|
50
|
|
|
->addOption('sort', null, InputOption::VALUE_OPTIONAL, '[null/ASC/DESC]. If argument orderby set, Default is ASC.') |
|
51
|
|
|
->addOption('orderby', null, InputOption::VALUE_OPTIONAL, '[null/name/path]. If argument sort set, Default is name.') |
|
52
|
|
|
->setDescription('Displays current routes for an application') |
|
53
|
|
|
->setHelp(<<<EOF |
|
54
|
|
|
The <info>%command.name%</info> displays the configured routes: |
|
55
|
|
|
<info>php %command.full_name%</info> |
|
56
|
|
|
EOF |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
62
|
|
|
|
|
63
|
|
|
$this->app->initialize(); |
|
64
|
|
|
$this->app->boot(); |
|
65
|
|
|
|
|
66
|
|
|
$console = new Application(); |
|
67
|
|
|
|
|
68
|
|
|
$filtername = $input->getArgument('name'); |
|
69
|
|
|
$sort = $input->getOption('sort'); |
|
70
|
|
|
$orderby = $input->getOption('orderby'); |
|
71
|
|
|
|
|
72
|
|
|
$table = $console->getHelperSet()->get('table'); |
|
73
|
|
|
$table->setHeaders(array('Name', 'Path', 'Pattern')); |
|
74
|
|
|
$table->setLayout(TableHelper::LAYOUT_DEFAULT); |
|
75
|
|
|
|
|
76
|
|
|
$controllers = $this->app['controllers']; |
|
77
|
|
|
$collection = $controllers->flush(); |
|
78
|
|
|
|
|
79
|
|
|
foreach ($collection as $name => $route) { |
|
80
|
|
|
if (!empty($filtername) && !preg_match("/$filtername/", $name)) { |
|
81
|
|
|
continue; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$requirements = array(); |
|
85
|
|
|
foreach ($route->getRequirements() as $key => $requirement) { |
|
86
|
|
|
// $requirements[] = $key . ' => ' . $requirement; |
|
|
|
|
|
|
87
|
|
|
$requirements[] = $requirement; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$table->addRow(array( |
|
|
|
|
|
|
91
|
|
|
$name, |
|
92
|
|
|
$route->getPath(), |
|
93
|
|
|
join(', ', $requirements) |
|
94
|
|
|
)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
$routes = $this->app['routes']->all(); |
|
99
|
|
|
|
|
100
|
|
|
// 引数で並び替える。 |
|
101
|
|
|
if (!empty($sort)) { |
|
102
|
|
|
$orderby = (!empty($orderby)) ? $orderby : "name"; |
|
103
|
|
|
} |
|
104
|
|
|
if (!empty($orderby)) { |
|
105
|
|
|
$sort = (!empty($sort)) ? $sort : "ASC"; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if (strtoupper($orderby) === "NAME") { |
|
109
|
|
|
if (strtoupper($sort) === "DESC") { |
|
110
|
|
|
krsort($routes); |
|
111
|
|
|
} else { |
|
112
|
|
|
ksort($routes); |
|
113
|
|
|
} |
|
114
|
|
|
} else if (strtoupper($orderby) === "PATH") { |
|
115
|
|
|
uasort($routes, function($a, $b) { |
|
|
|
|
|
|
116
|
|
|
return strcmp($a->getPattern(), $b->getPattern()); |
|
117
|
|
|
}); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
$maxName = 4; |
|
121
|
|
|
$maxMethod = 6; |
|
122
|
|
|
foreach ($routes as $name => $route) { |
|
123
|
|
|
if (!empty($filtername) && !preg_match("/$filtername/", $name)) { |
|
124
|
|
|
unset($routes[$name]); |
|
125
|
|
|
continue; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$requirements = $route->getRequirements(); |
|
129
|
|
|
$method = isset($requirements['_method']) |
|
130
|
|
|
? strtoupper(is_array($requirements['_method']) |
|
131
|
|
|
? implode(', ', $requirements['_method']) : $requirements['_method'] |
|
132
|
|
|
) |
|
133
|
|
|
: 'ANY'; |
|
134
|
|
|
|
|
135
|
|
|
if (strlen($name) > $maxName) { |
|
136
|
|
|
$maxName = strlen($name); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
if (strlen($method) > $maxMethod) { |
|
140
|
|
|
$maxMethod = strlen($method); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
foreach ($routes as $name => $route) { |
|
145
|
|
|
$requirements = $route->getRequirements(); |
|
146
|
|
|
$method = isset($requirements['_method']) |
|
147
|
|
|
? strtoupper(is_array($requirements['_method']) |
|
148
|
|
|
? implode(', ', $requirements['_method']) : $requirements['_method'] |
|
149
|
|
|
) |
|
150
|
|
|
: 'ANY'; |
|
151
|
|
|
|
|
152
|
|
|
$table->addRow(array( |
|
153
|
|
|
$name, |
|
154
|
|
|
$route->getPattern(), |
|
155
|
|
|
$method, |
|
156
|
|
|
)); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
$table->render($output); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
|