-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] [Routing] Added --sort to debug:router #36579
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
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.
LGTM, just some nitpicking.
src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php
Outdated
Show resolved
Hide resolved
I think this PR gives the wrong impression. First of all routes are not only sorted by priority but also by the order your define them in by default. So the description is not correct. |
@Tobion Yes, probably "priority" is not the best name because by default |
460477f
to
2b9e044
Compare
Something went wrong here. |
Sorry @fabpot, I was trying to fix the failing tests without noticing that the main build was failing too. I will try to cleanup the git mess otherwise I'll drop this PR and submit a new one. |
6c67ce1
to
ced94da
Compare
src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Outdated
Show resolved
Hide resolved
7af952f
to
49029ae
Compare
if ('name' === $propertyName) { | ||
ksort($sortedRoutes); | ||
} elseif ('path' === $propertyName) { | ||
uasort($sortedRoutes, function ($a, $b) { return $a->getPath() <=> $b->getPath(); }); |
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.
please add the type for $a and $b
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.
if routes have the same path but different prio, this can result is routes getting mixed up. sorting will only be stable in php 8: https://wiki.php.net/rfc/stable_sorting
So we would need to implement the stable part ourselves prio to php 8.
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.
Ok, I'll refactor the test to verify the stability
private function sortRoutes(RouteCollection $routes, string $propertyName): RouteCollection | ||
{ | ||
$sortedRoutes = $routes->all(); | ||
if ('name' === $propertyName) { |
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 a switch
statement would be a better fit here
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.
Ok I'm going to change this
src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Outdated
Show resolved
Hide resolved
$tester->execute(['--sort' => null], ['decorated' => false]); | ||
} | ||
|
||
public function testSortingByPriorityWithDuplicatePath() |
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 this test is useless as it doesn't cover anything new
$this->assertStringNotContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true)); | ||
} | ||
|
||
public function testSortingByNameWithDuplicatePath() |
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 this test is useless as it doesn't cover anything new
$this->assertStringContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true)); | ||
} | ||
|
||
public function testSortingByPathWithDuplicatePath() |
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.
this test should actually also make sure the routes with the same path stay in the correct order as before (check routes names) as I mention in the stable sorting comment
@vjandrea Can you take the latest comments into account? |
@vjandrea It looks like you did some work, but I still see some feedback that are not taken into account. Do you plan to finish this PR soon? |
@vjandrea Still willing to finish this PR? |
Yes Fabien, still wishing to complete it but I'm really busy with a tight
deadline in this moment, I think I'll have time at the beginning of
October. Thanks
Il sab 19 set 2020, 09:16 Fabien Potencier <notifications@github.com> ha
scritto:
… @vjandrea <https://github.com/vjandrea> Still willing to finish this PR?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#36579 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAMQKTK2WFKUY3P4UWI5L5LSGRLFZANCNFSM4MQX2ZFQ>
.
|
Re-reading the whole thing, I think that having a |
This PR adds a
--sort
functionality toconsole debug:router.
It allows to sort by name, path or priority (default).