Skip to content

[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

Conversation

Simperfit
Copy link
Contributor

@Simperfit Simperfit commented Feb 9, 2018

Q A
Branch? 4.1
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
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.
img_3271

@Simperfit
Copy link
Contributor Author

Travis failure is unrelated

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Feb 9, 2018
@dunglas
Copy link
Member

dunglas commented Feb 9, 2018

Can you add a test please?

@Simperfit
Copy link
Contributor Author

@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.

@Simperfit Simperfit force-pushed the feature/search-if-a-route-name-match-a-route-in-debug-router branch 7 times, most recently from 3a5df79 to d002dd6 Compare February 14, 2018 12:03
@Simperfit
Copy link
Contributor Author

Status: needs review

@dunglas test added

@Simperfit Simperfit force-pushed the feature/search-if-a-route-name-match-a-route-in-debug-router branch 2 times, most recently from 41fb042 to a9e228d Compare February 15, 2018 08:12
@Simperfit
Copy link
Contributor Author

New test added that test the whole behaviour of the search.

@Simperfit Simperfit force-pushed the feature/search-if-a-route-name-match-a-route-in-debug-router branch from a9e228d to 6afe696 Compare February 15, 2018 08:29
@@ -142,4 +150,17 @@ private function extractCallable(Route $route)
} catch (\InvalidArgumentException $e) {
}
}

private function findRouteNameContaining(string $name, RouteCollection $routes)
Copy link
Member

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.

@@ -79,6 +80,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$routes = $this->router->getRouteCollection();

if ($name) {
$matchingRoutes = $this->findRouteNameContaining($name, $routes);

if (!empty($matchingRoutes) && !$route = $routes->get($name)) {
Copy link
Member

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)) {
Copy link
Member

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).

@Simperfit Simperfit force-pushed the feature/search-if-a-route-name-match-a-route-in-debug-router branch from 6afe696 to 29561eb Compare February 15, 2018 08:47
@@ -79,6 +80,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$routes = $this->router->getRouteCollection();

if ($name) {
$matchingRoutes = $this->findRouteNameContaining($name, $routes);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@chalasr
Copy link
Member

chalasr commented Mar 6, 2018

I suggest to drop the existing RouterDebugCommand test, it is semi-functional (use a mocked kernel) and all of its tests are covered by the one added here.

@althaus
Copy link
Contributor

althaus commented Mar 8, 2018

@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.

@Simperfit Simperfit force-pushed the feature/search-if-a-route-name-match-a-route-in-debug-router branch from e30c1cd to 635ce3a Compare March 14, 2018 08:47
@Simperfit
Copy link
Contributor Author

@chalasr @dunglas PR rebased, test fixed, semi-functional test deleted.

@Simperfit
Copy link
Contributor Author

Travis failure is unrelated.

@@ -17,7 +17,8 @@ CHANGELOG
is either the service ID or the FQCN of the controller.
* Deprecated `Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser`
* The `container.service_locator` tag of `ServiceLocator`s is now autoconfigured.

* Add the ability to search a route in `debug:router`.

Copy link
Member

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);
Copy link
Member

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?

@Simperfit Simperfit force-pushed the feature/search-if-a-route-name-match-a-route-in-debug-router branch from 635ce3a to 0187162 Compare March 21, 2018 08:33
@Simperfit
Copy link
Contributor Author

@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);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this part.

@Simperfit Simperfit force-pushed the feature/search-if-a-route-name-match-a-route-in-debug-router branch from 0187162 to 5e6007d Compare March 21, 2018 08:42
@Simperfit
Copy link
Contributor Author

Status: Needs Review

$this->assertContains('/session', $display);
}

public function testDumpOneRoutes()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo. testDumpOneRoutes -> testDumpOneRoute

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Simperfit Simperfit force-pushed the feature/search-if-a-route-name-match-a-route-in-debug-router branch from 5e6007d to ef0df02 Compare March 21, 2018 09:40
@fabpot
Copy link
Member

fabpot commented Mar 21, 2018

Thank you @Simperfit.

@fabpot fabpot merged commit ef0df02 into symfony:master Mar 21, 2018
fabpot added a commit that referenced this pull request Mar 21, 2018
… 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.
![img_3271](https://user-images.githubusercontent.com/3451634/36034017-e60cbfda-0db2-11e8-841a-60bc75b0b631.jpeg)

Commits
-------

ef0df02 [FrameworkBundle] feature: add the ability to search a route
@Simperfit Simperfit deleted the feature/search-if-a-route-name-match-a-route-in-debug-router branch March 21, 2018 10:20
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Mar 23, 2018
…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
@fabpot fabpot mentioned this pull request May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants