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 e7ac4f5
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/Illuminate/Routing/AbstractRouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,46 @@ 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);
}
}

return $symfonyRoutes;
}

$symfonyRoutes->add($name, $route->toSymfonyRoute());
/**
* Add a route to the SymfonyRouteCollection instance.
*
* @param \Symfony\Component\Routing\RouteCollection $symfonyRoutes
* @param \Illuminate\Routing\Route $route
* @return \Symfony\Component\Routing\RouteCollection
*/
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 e7ac4f5

Please sign in to comment.