/**
  * @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;
 }
예제 #2
0
 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());
 }
 /**
  * Test exception if one breadcrumb is missing its label
  */
 public function testMalformedBreadcrumb()
 {
     $collection = new RouteCollection();
     $route1Crumbs = array('breadcrumb' => array('parent_route' => 'bar'));
     $route2Crumbs = array('breadcrumb' => array('label' => 'Bar'));
     $collection->add('foo', new Route('/foo', array(), array(), $route1Crumbs));
     $collection->add('bar', new Route('/bar', array(), array(), $route2Crumbs));
     $this->delegatingLoader->expects($this->once())->method('load')->will($this->returnValue($collection));
     $this->setExpectedException('\\InvalidArgumentException');
     $this->loader->load('foobar');
 }
 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);
 }
 /**
  * Test behaviour of loader when breadcrumbs are configured circular (a -> b -> a etc.)
  */
 public function testCircularBreadcrumbs()
 {
     $routeFooName = 'foo';
     $routeBarName = 'bar';
     $routeFooCrumbs = array('breadcrumb' => array('label' => 'Foo', 'parent_route' => $routeBarName));
     $routeBarCrumbs = array('breadcrumb' => array('label' => 'Bar', 'parent_route' => $routeFooName));
     $collection = new RouteCollection();
     $collection->add($routeFooName, new Route('/foo', array(), array(), $routeFooCrumbs));
     $collection->add($routeBarName, new Route('/bar', array(), array(), $routeBarCrumbs));
     $this->delegatingLoader->expects($this->once())->method('load')->will($this->returnValue($collection));
     $this->setExpectedException('\\LogicException');
     $this->loader->load('foobar');
 }
예제 #6
0
 /**
  * @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;
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
 /**
  * @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;
 }
예제 #9
0
 /**
  * {@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;
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel)
 {
     return $resolver->resolve(__DIR__ . '/../Resources/config/routing.yml')->load(__DIR__ . '/../Resources/config/routing.yml');
 }