Exemplo n.º 1
0
 /**
  * Get a route collection for all routes associated to a page controller.
  *
  * @param PageInterface $page
  *
  * @return RouteCollection
  *
  * @throws RouteNotFoundException
  */
 protected function getPageControllerRoutes(PageInterface $page)
 {
     // Page Controller found, attach specified routes
     $pageController = $this->routeManager->get($page->getPageControllerPath());
     $storedRoutes = $this->storage->getRoutes();
     $collection = new RouteCollection();
     foreach ($pageController->getRoutes() as $routeName) {
         if (!isset($storedRoutes[$routeName])) {
             throw new RouteNotFoundException(sprintf('Could not find route in page controller config: "%s"', $routeName));
         }
         $route = $storedRoutes[$routeName];
         // Mark the index route
         if ($route->getPath() === '/') {
             $route->addDefaults(['_controller_index' => true]);
         }
         $collection->add($routeName, $route);
     }
     // Clone the collection so we aren't altering the stored routes
     $clonedCollection = clone $collection;
     // Add the page's prefix
     $clonedCollection->addPrefix($page->getPath());
     $clonedCollection->addDefaults(['_page' => $page]);
     return $clonedCollection;
 }