-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[FrameworkBundle] feature: add the ability to search a route #26121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FrameworkBundle] feature: add the ability to search a route #26121
Conversation
|
Travis failure is unrelated |
|
Can you add a test please? |
|
@dunglas I will do, I'm searching a way to add one, I have to look on other command's tests to test the choices. |
3a5df79 to
d002dd6
Compare
|
Status: needs review @dunglas test added |
41fb042 to
a9e228d
Compare
|
New test added that test the whole behaviour of the search. |
a9e228d to
6afe696
Compare
| } | ||
| } | ||
|
|
||
| private function findRouteNameContaining(string $name, RouteCollection $routes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the : array return type.
| if ($name) { | ||
| $matchingRoutes = $this->findRouteNameContaining($name, $routes); | ||
|
|
||
| if (!empty($matchingRoutes) && !$route = $routes->get($name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified in=
$matchingRoutes = $this->findRouteNameContaining($name, $routes)
if ($matchingRoutes && !$route = $routes->get($name) {| { | ||
| $foundRoutesNames = array(); | ||
| foreach ($routes as $routeName => $route) { | ||
| if (false === stripos($routeName, $name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe can you invert the test, and put $foundRoutesNames[] = $routeName; in the if block to save 1 line (nitpicking).
6afe696 to
29561eb
Compare
| $routes = $this->router->getRouteCollection(); | ||
|
|
||
| if ($name) { | ||
| $matchingRoutes = $this->findRouteNameContaining($name, $routes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would first try to get the route by exact name before searching route names. It is useless to search the matching routes if we already have a valid name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
I suggest to drop the existing |
|
@chalasr Oh... didn't know about the change in the release cycles and the limit of 5 minors. So I'll just overload the command with my own version of this change. |
e30c1cd to
635ce3a
Compare
|
Travis failure is unrelated. |
| * The `container.service_locator` tag of `ServiceLocator`s is now autoconfigured. | ||
|
|
||
| * Add the ability to search a route in `debug:router`. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra spaces I believe
| if (!$route = $routes->get($name)) { | ||
| if (!($route = $routes->get($name)) && $matchingRoutes = $this->findRouteNameContaining($name, $routes)) { | ||
| $default = 1 === count($matchingRoutes) ? $matchingRoutes[0] : null; | ||
| $name = $io->choice('Select one of the following routes to display its information', $matchingRoutes, $default); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Select one of the matching routes?
635ce3a to
0187162
Compare
|
@fabpot done. |
| if (!$route = $routes->get($name)) { | ||
| if (!($route = $routes->get($name)) && $matchingRoutes = $this->findRouteNameContaining($name, $routes)) { | ||
| $default = 1 === count($matchingRoutes) ? $matchingRoutes[0] : null; | ||
| $name = $io->choice('Select one of the matching routes to display its information', $matchingRoutes, $default); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the to display its information is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this part.
0187162 to
5e6007d
Compare
|
Status: Needs Review |
| $this->assertContains('/session', $display); | ||
| } | ||
|
|
||
| public function testDumpOneRoutes() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo. testDumpOneRoutes -> testDumpOneRoute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
5e6007d to
ef0df02
Compare
|
Thank you @Simperfit. |
… route (Simperfit) This PR was merged into the 4.1-dev branch. Discussion ---------- [FrameworkBundle] feature: add the ability to search a route | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #26033 | License | MIT | Doc PR | symfony/symfony-docs#9236 This add the ability to search a route in the debug:router command.  Commits ------- ef0df02 [FrameworkBundle] feature: add the ability to search a route
…a route (Simperfit) This PR was merged into the master branch. Discussion ---------- [FrameworkBundle] feature: add the ability to search for a route The PR add the documentation for core's PR symfony/symfony#26121 Commits ------- 2d781a8 feature: add the ability to search for a route
This add the ability to search a route in the debug:router command.
