Ejemplo n.º 1
0
 /**
  * Returns true if this class supports the given resource.
  *
  * @param  mixed $resource A resource
  *
  * @return Boolean true if this class supports the given resource, false otherwise
  */
 public function supports($resource)
 {
     foreach ($this->resolver->getLoaders() as $loader) {
         if ($loader->supports($resource)) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Router constructor.
  *
  * @param LoaderResolverInterface $resolver
  * @param array                   $resources
  * @param MethodCollection|null   $collection
  *
  * @param array                   $context
  */
 public function __construct(LoaderResolverInterface $resolver, array $resources = [], MethodCollection $collection = null, array $context = [])
 {
     $this->collection = $collection;
     if (null === $this->collection) {
         $this->collection = new MethodCollection();
     }
     foreach ($resources as $resource) {
         $loader = $resolver->resolve($resource);
         if (false === $loader) {
             throw new \RuntimeException(sprintf('Could not resolve loader for resource "%s"', $resource));
         }
         $this->collection->addCollection($loader->load($resource));
     }
     foreach ($context as $item) {
         $this->collection->addContext($item);
     }
 }