Skip to content

[Routing] Add a 'has' method to the RouteCollection #19270

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

Closed
wants to merge 2 commits into from
Closed

[Routing] Add a 'has' method to the RouteCollection #19270

wants to merge 2 commits into from

Conversation

voronkovich
Copy link
Contributor

Q A
Branch? "master"
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

This method is usefull when you want just to check whether a route exists:

if ($router->getRouteCollection()->has('some_route')) {
    // ...
}

@HeahDude
Copy link
Contributor

HeahDude commented Jul 2, 2016

@wouterj
Copy link
Member

wouterj commented Jul 2, 2016

Not 100% related to this PR, but never use Router#getRouteCollection(). This method will rebuilt all routing cache, meaning your application rebuilds routing cache each request and it'll be very slow: #7368

@voronkovich
Copy link
Contributor Author

@wouterj, thanks for the heads up! So, there is no way to check whether a route exists at runtime...

@wouterj
Copy link
Member

wouterj commented Jul 2, 2016

@voronkovich yeah, catching the exception is knowing whether the route exists or not:

use Symfony\Component\Routing\Exception\RouteNotFoundException;

try {
    dump($router->generate('some_route'));
} catch (RouteNotFoundException $e) {
    dump('Oh noes, route "some_route" doesn't exists!');
}

@fabpot
Copy link
Member

fabpot commented Jul 2, 2016

Closing as as @wouterj mentioned, the route collection is an implementation detail that you should never use directly.

@fabpot fabpot closed this Jul 2, 2016
@wouterj
Copy link
Member

wouterj commented Jul 2, 2016

@fabpot do you know the reason why getRouteCollection() is part of the RouterInterface? (seems like you added it without any future references in 1467bdb ) To me, it seems like this one should not be part of any interface and marked as @internal on the Router class (it's only used on the debug commands and web profiler)

@fabpot
Copy link
Member

fabpot commented Jul 2, 2016

@wouterj That's very old :) I think this can be deprecated so that we can remove it in 4.0.

@stof
Copy link
Member

stof commented Jul 4, 2016

@wouterj the getRouteCollection was necessary for the old implementation of the router cache warming.

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.

6 participants