Skip to content

Commit

Permalink
Move fallback routes to the end of symfony routes collection
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Feb 14, 2020
1 parent 475635e commit 2673a27
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/Illuminate/Routing/AbstractRouteCollection.php
Expand Up @@ -166,20 +166,39 @@ public function dumper()
public function toSymfonyRouteCollection()
{
$symfonyRoutes = new SymfonyRouteCollection();
$routes = $this->getRoutes();

// Because we need to make sure that fallback routes are always placed as last
// we'll first iterate over the regular routes and add them to the symfony
// routes collection. Then we'll do the same thing for the fallback routes.
foreach ($routes as $route) {
if (! $route->isFallback) {
$symfonyRoutes = $this->addToSymfonyRoutesCollection($symfonyRoutes, $route);
}
}

foreach ($this->getRoutes() as $route) {
// If the route doesn't have a name, we'll generate one for it
// and re-add the route to the collection. This way we can
// add the route to the Symfony route collection.
if (! $name = $route->getName()) {
$route->name($name = $this->generateRouteName());

$this->add($route);
foreach ($routes as $route) {
if ($route->isFallback) {
$symfonyRoutes = $this->addToSymfonyRoutesCollection($symfonyRoutes, $route);
}
}

$symfonyRoutes->add($name, $route->toSymfonyRoute());
return $symfonyRoutes;
}

protected function addToSymfonyRoutesCollection(SymfonyRouteCollection $symfonyRoutes, Route $route)
{
// If the route doesn't have a name, we'll generate one for it
// and re-add the route to the collection. This way we can
// add the route to the Symfony route collection.
if (! $name = $route->getName()) {
$route->name($name = $this->generateRouteName());

$this->add($route);
}

$symfonyRoutes->add($name, $route->toSymfonyRoute());

return $symfonyRoutes;
}

Expand Down

0 comments on commit 2673a27

Please sign in to comment.