Skip to content

Commit 59b7601

Browse files
committed
Tweaking the routes command slightly and adding the rest of the docblocks.
Signed-off-by: Jason Lewis <[email protected]>
1 parent f67775e commit 59b7601

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

src/Console/Command/Routes.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function getRoutes()
6969
'uri' => implode('|', $route->methods()).' '.$route->uri(),
7070
'name' => $route->getName(),
7171
'action' => $route->getActionName(),
72-
'version' => implode(', ', $route->versions()),
72+
'versions' => implode(', ', $route->versions()),
7373
'protected' => $route->isProtected() ? 'Yes' : 'No',
7474
'scopes' => implode(', ', $route->scopes())
7575
]);
@@ -109,28 +109,62 @@ protected function getOptions()
109109
return array_merge(
110110
parent::getOptions(),
111111
[
112-
['versions', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by version'],
113-
['scopes', 'S', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Filter the routes by scopes', null],
112+
['versions', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Filter the routes by version'],
113+
['scopes', 'S', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Filter the routes by scopes'],
114114
]
115115
);
116116
}
117117

118+
/**
119+
* Filter the route by its path.
120+
*
121+
* @param array $route
122+
*
123+
* @return bool
124+
*/
118125
protected function filterByPath(array $route)
119126
{
120127
return str_contains($route['uri'], $this->option('path'));
121128
}
122129

130+
/**
131+
* Filter the route by its versions.
132+
*
133+
* @param array $route
134+
*
135+
* @return bool
136+
*/
123137
protected function filterByVersions(array $route)
124138
{
125-
return str_contains($route['version'], $this->option('versions'));
139+
foreach ($this->option('versions') as $version) {
140+
if (str_contains($route['versions'], $version)) {
141+
return true;
142+
}
143+
}
144+
145+
return false;
126146
}
127147

148+
/**
149+
* Filter the route by its name.
150+
*
151+
* @param array $route
152+
*
153+
* @return bool
154+
*/
128155
protected function filterByName(array $route)
129156
{
130157
return str_contains($route['name'], $this->option('name'));
131158
}
132159

133-
protected function filterByScope(array $route)
160+
/**
161+
* Filter the route by its scopes.
162+
*
163+
* @param array $route
164+
*
165+
* @return bool
166+
*/
167+
protected function filterByScopes(array $route)
134168
{
135169
foreach ($this->option('scopes') as $scope) {
136170
if (str_contains($route['scopes'], $scope)) {

0 commit comments

Comments
 (0)