/** * @param mixed $resource * @param null $type * @return \Symfony\Component\Routing\RouteCollection * @throws \RuntimeException */ public function load($resource, $type = null) { $routes = new RouteCollection(); /* * For each core bunle then for each module */ // CoreBundle $loader = $this->resolver->resolve('@EtuCoreBundle/Api/Resource/', 'annotation'); if ($loader) { $routes->addCollection($loader->load('@EtuCoreBundle/Api/Resource/', 'annotation')); } // UserBundle $loader = $this->resolver->resolve('@EtuUserBundle/Api/Resource/', 'annotation'); if ($loader) { $routes->addCollection($loader->load('@EtuUserBundle/Api/Resource/', 'annotation')); } /** @var $module Module */ foreach ($this->kernel->getModulesDefinitions() as $module) { $routing = $module->getApiRouting(); $loader = $this->resolver->resolve($routing['resource'], $routing['type']); if ($loader) { $routes->addCollection($loader->load($routing['resource'], $routing['type'])); } } return $routes; }
public function testLoad() { $importedRouteCollection = new RouteCollection(); $importedRouteCollection->add('route1', new Route('/example/route1')); $importedRouteCollection->add('route2', new Route('/route2')); $portal1 = new Portal(); $portal1->setKey('sulu_lo'); $portal2 = new Portal(); $portal2->setKey('sulu_com'); $portalInformations = [new PortalInformation(null, null, $portal1, null, 'sulu.io/de'), new PortalInformation(null, null, $portal2, null, 'sulu.com')]; $this->loaderResolver->resolve(Argument::any(), Argument::any())->willReturn($this->loader->reveal()); $this->loader->load(Argument::any(), Argument::any())->willReturn($importedRouteCollection); $this->webspaceManager->getPortalInformations(Argument::any())->willReturn($portalInformations); $routeCollection = $this->portalLoader->load('', 'portal'); $this->assertCount(4, $routeCollection); $routes = $routeCollection->getIterator(); $this->assertArrayHasKey('sulu.io/de.route1', $routes); $this->assertArrayHasKey('sulu.io/de.route2', $routes); $this->assertArrayHasKey('sulu.com.route1', $routes); $this->assertArrayHasKey('sulu.com.route2', $routes); $this->assertEquals('/de/example/route1', $routeCollection->get('sulu.io/de.route1')->getPath()); $this->assertEquals('/de/route2', $routeCollection->get('sulu.io/de.route2')->getPath()); $this->assertEquals('/example/route1', $routeCollection->get('sulu.com.route1')->getPath()); $this->assertEquals('/route2', $routeCollection->get('sulu.com.route2')->getPath()); }
protected function loadRouteCollectionFromFile(string $path) : RouteCollection { if (!file_exists($path)) { throw new FileNotFoundException(sprintf('File "%s" was not found.', $path)); } $loader = $this->loaderResolver->resolve($path); if (null === $loader) { return new RouteCollection(); } return $loader->load($path); }
/** * @param mixed $resource * @param null $type * @return \Symfony\Component\Routing\RouteCollection * @throws \RuntimeException */ public function load($resource, $type = null) { if ($this->loaded) { throw new \RuntimeException('Do not add this loader twice'); } $routes = new RouteCollection(); /** @var $module Module */ foreach ($this->kernel->getModulesDefinitions() as $module) { $routing = $module->getRouting(); $loader = $this->resolver->resolve($routing['resource'], $routing['type']); if ($loader) { $routes->addCollection($loader->load($routing['resource'], $routing['type'])); } } return $routes; }
/** * Returns the loader for a resource. * * @param Resource $resource The resource. * * @return LoaderInterface|null The resource loader. */ public function resolve(Resource $resource) { if ($resource instanceof ResourceSupport) { $loader = $this->resolver->resolve($resource->getSupportResource(), $resource->getSupportType()); } else { $loader = $this->resolver->resolve($resource->getResource(), $resource->getType()); } return false === $loader ? null : $loader; }
/** * @param array $resources * * @return RouteCollection */ private function importResources(array $resources) { $collection = new RouteCollection(); foreach ($resources as $resource => $type) { if (false !== ($loader = $this->resolver->resolve($resource, $type))) { $collection->addCollection($loader->load($resource, $type)); } } return $collection; }
/** * {@inheritDoc} */ public function resolve($resource, $type = null) { if ($this->supports($resource, $type)) { return $this; } $loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type); if (false === $loader) { throw new FileLoaderLoadException($resource); } return $loader; }
/** * {@inheritdoc} */ public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel) { return $resolver->resolve(__DIR__ . '/../Resources/config/routing.yml')->load(__DIR__ . '/../Resources/config/routing.yml'); }