Groups consecutive routes having the same host regex.
The result is a collection of collections of routes having the same host regex.
RouteCollection $routes A flat RouteCollection:
DumperCollection A collection with routes grouped by host regex in sub-collections
private function groupRoutesByHostRegex(RouteCollection $routes) {
$groups = new DumperCollection();
$currentGroup = new DumperCollection();
$currentGroup
->setAttribute('host_regex', null);
$groups
->add($currentGroup);
foreach ($routes as $name => $route) {
$hostRegex = $route
->compile()
->getHostRegex();
if ($currentGroup
->getAttribute('host_regex') !== $hostRegex) {
$currentGroup = new DumperCollection();
$currentGroup
->setAttribute('host_regex', $hostRegex);
$groups
->add($currentGroup);
}
$currentGroup
->add(new DumperRoute($name, $route));
}
return $groups;
}