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

  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 array $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.     public function resolve(mixed $resourcestring $type null): LoaderInterface|false
  35.     {
  36.         foreach ($this->loaders as $loader) {
  37.             if ($loader->supports($resource$type)) {
  38.                 return $loader;
  39.             }
  40.         }
  41.         return false;
  42.     }
  43.     public function addLoader(LoaderInterface $loader)
  44.     {
  45.         $this->loaders[] = $loader;
  46.         $loader->setResolver($this);
  47.     }
  48.     /**
  49.      * Returns the registered loaders.
  50.      *
  51.      * @return LoaderInterface[]
  52.      */
  53.     public function getLoaders(): array
  54.     {
  55.         return $this->loaders;
  56.     }
  57. }