Skip to content
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

Create route through an iterator #28418

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RouteRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function resource($name, $controller, array $options = [])
/**
* Create a route group with shared attributes.
*
* @param \Closure|string $callback
* @param \Closure|string|iterable $callback
* @return void
*/
public function group($callback)
Expand Down
21 changes: 20 additions & 1 deletion src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Routing;

use Iterator;
use Closure;
use ArrayObject;
use JsonSerializable;
Expand Down Expand Up @@ -360,7 +361,7 @@ public function apiResource($name, $controller, array $options = [])
* Create a route group with shared attributes.
*
* @param array $attributes
* @param \Closure|string $routes
* @param \Closure|string|iterable $routes
* @return void
*/
public function group(array $attributes, $routes)
Expand All @@ -370,8 +371,26 @@ public function group(array $attributes, $routes)
// Once we have updated the group stack, we'll load the provided routes and
// merge in the group's attributes when the routes are created. After we
// have created the routes, we will pop the attributes off the stack.

if($routes instanceof Iterator){
$this->groupIterable($routes);
return ;
}

$this->loadRoutes($routes);
array_pop($this->groupStack);
}

/**
* Create a route group from an iterator with shared attributes.
*
* @param Iterator $routes
* @return void
*/
public function groupIterable(\Iterator $routes){
foreach($routes as $route) {
$this->loadRoutes($route);
}
array_pop($this->groupStack);
}

Expand Down