*/ class SiteRouteLoader extends Loader { protected NavigationRepositoryQuery $navigationQuery; protected $isLoaded = false; public function __construct(NavigationRepositoryQuery $navigationQuery) { $this->navigationQuery = $navigationQuery; } public function load($resource, ?string $type = null) { if (true === $this->isLoaded) { throw new \RuntimeException('Do not add the "extra" loader twice'); } $routes = new RouteCollection(); $navigations = $this->navigationQuery->find(); foreach ($navigations as $navigation) { foreach ($navigation->getMenus() as $menu) { foreach ($menu->getRootNode()->getAllChildren() as $node) { $requirements = []; $defaults = [ '_controller' => PageController::class.'::show', '_node' => $node->getId(), '_menu' => $menu->getId(), '_page' => $node->getPage() ? $node->getPage()->getId() : null, '_navigation' => $navigation->getId(), ]; $route = new Route($node->getUrl(), $defaults, $requirements); $route->setHost($navigation->getDomain()); $routes->add('site_page_'.$node->getId(), $route); } } } $this->isLoaded = true; return $routes; } public function supports($resource, string $type = null) { return 'extra' === $type; } }