This loader acts as an array of LoaderInterface objects - each having a chance to load a given resource (handled by the resolver)
Author: Fabien Potencier (fabien.potencier@symfony-project.com)
Inheritance: extends Loader
 /**
  * @covers Symfony\Component\Routing\Loader\DelegatingLoader::load
  */
 public function testLoad()
 {
     $resolver = new LoaderResolver(array(new ClosureLoader()));
     $loader = new DelegatingLoader($resolver);
     $route = new Route('/');
     $routes = $loader->load(function () use($route) {
         $routes = new RouteCollection();
         $routes->add('foo', $route);
         return $routes;
     });
     $this->assertSame($route, $routes->get('foo'), '->load() loads a resource using the loaders from the resolver');
     try {
         $loader->load('foo.foo');
         $this->fail('->load() throws an \\InvalidArgumentException if the resource cannot be loaded');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an \\InvalidArgumentException if the resource cannot be loaded');
     }
 }
 /**
  * Loads a resource.
  *
  * @param  mixed $resource A resource
  *
  * @return RouteCollection A RouteCollection instance
  */
 public function load($resource)
 {
     $collection = parent::load($resource);
     foreach ($collection->getRoutes() as $name => $route) {
         if ($controller = $route->getDefault('_controller')) {
             try {
                 $controller = $this->converter->fromShortNotation($controller);
             } catch (\Exception $e) {
                 throw new \RuntimeException(sprintf('%s (for route "%s" in resource "%s")', $e->getMessage(), $name, is_string($resource) ? $resource : 'RESOURCE'), $e->getCode(), $e);
             }
             $route->setDefault('_controller', $controller);
         }
     }
     return $collection;
 }
Example #3
0
 /**
  * Loads a resource.
  *
  * @param  mixed $resource A resource
  *
  * @return RouteCollection A RouteCollection instance
  */
 public function load($resource)
 {
     $collection = parent::load($resource);
     foreach ($collection->getRoutes() as $name => $route) {
         if ($controller = $route->getDefault('_controller')) {
             try {
                 $controller = $this->converter->fromShortNotation($controller);
             } catch (\Exception $e) {
                 // unable to optimize unknown notation
             }
             $route->setDefault('_controller', $controller);
         }
     }
     return $collection;
 }