public function testNestedRouteCollection()
 {
     $collection = new RouteCollection();
     $collection->add('home', new Route('/'));
     $collection2 = new RouteCollection('/admin');
     $collection2->add('dashboard', new Route('/dashboard'));
     $collection3 = new RouteCollection('/dashboard');
     $collection3->add('dashboard-monitoring', (new Route('/monitoring'))->secureOnly());
     $collection2->addCollection($collection3);
     $collection->addCollection($collection2);
     $this->assertArrayHasKey('dashboard', $collection->all());
     $this->assertTrue($collection->get('dashboard')->getPath() === '/admin/dashboard');
     $this->assertTrue($collection->get('dashboard-monitoring')->getPath() === '/admin/dashboard/monitoring');
     $this->assertTrue($collection->get('dashboard-monitoring')->getSchema()->has('http') === false);
     $this->assertTrue($collection->get('dashboard-monitoring')->getSchema()->has('https'));
 }
 /**
  * Listen RequestContext and trigger handler.
  *
  * @param RequestContext $request
  */
 public function listen(RequestContext $request)
 {
     if (null === $this->handler) {
         throw new RuntimeException('There are not router handler found.');
     }
     $found = null;
     foreach ($this->collection->all() as $route) {
         if (true === $this->isMatch($route, $request)) {
             $found = $route;
             break;
         }
     }
     $previous = 0 === count($this->requests) ? null : $this->getRequest(count($this->requests) - 1);
     $this->requests[] = $request;
     if ($this->handler instanceof RouterHandlerInterface) {
         $this->handler->handleRouteRequest($found, $request, $this, $previous);
     } else {
         $caller = Closure::bind($this->handler, null);
         $caller($found, $request, $this, $previous);
     }
 }
 /**
  * Add a route collection by append all routes on that collection.
  *
  * @param RouteCollection $collection
  *
  * @return static
  */
 public function addCollection(RouteCollection $collection)
 {
     foreach ($collection->all() as $name => $route) {
         $this->add($name, $route);
     }
     return $this;
 }