public function testGetRoot() { $a = new DumperCollection(); $b = new DumperCollection(); $a->add($b); $c = new DumperCollection(); $b->add($c); $d = new DumperCollection(); $c->add($d); $this->assertSame($a, $c->getRoot()); }
/** * Groups consecutive routes having the same host regex. * * The result is a collection of collections of routes having the same host regex. * * @param RouteCollection $routes A flat RouteCollection * * @return 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; }