vendor/symfony/config/Loader/LoaderResolver.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Config\Loader;
  11. /**
  12.  * LoaderResolver selects a loader for a given resource.
  13.  *
  14.  * A resource can be anything (e.g. a full path to a config file or a Closure).
  15.  * Each loader determines whether it can load a resource and how.
  16.  *
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  */
  19. class LoaderResolver implements LoaderResolverInterface
  20. {
  21.     /**
  22.      * @var LoaderInterface[] An array of LoaderInterface objects
  23.      */
  24.     private $loaders = [];
  25.     /**
  26.      * @param LoaderInterface[] $loaders An array of loaders
  27.      */
  28.     public function __construct(array $loaders = [])
  29.     {
  30.         foreach ($loaders as $loader) {
  31.             $this->addLoader($loader);
  32.         }
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      */
  37.     public function resolve($resourcestring $type null)
  38.     {
  39.         foreach ($this->loaders as $loader) {
  40.             if ($loader->supports($resource$type)) {
  41.                 return $loader;
  42.             }
  43.         }
  44.         return false;
  45.     }
  46.     public function addLoader(LoaderInterface $loader)
  47.     {
  48.         $this->loaders[] = $loader;
  49.         $loader->setResolver($this);
  50.     }
  51.     /**
  52.      * Returns the registered loaders.
  53.      *
  54.      * @return LoaderInterface[]
  55.      */
  56.     public function getLoaders()
  57.     {
  58.         return $this->loaders;
  59.     }
  60. }