vendor/symfony/src/Symfony/Component/Config/Loader/LoaderResolver.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony package.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace Symfony\Component\Config\Loader;
       
    13 
       
    14 /**
       
    15  * LoaderResolver selects a loader for a given resource.
       
    16  *
       
    17  * A resource can be anything (e.g. a full path to a config file or a Closure).
       
    18  * Each loader determines whether it can load a resource and how.
       
    19  *
       
    20  * @author Fabien Potencier <fabien@symfony.com>
       
    21  */
       
    22 class LoaderResolver implements LoaderResolverInterface
       
    23 {
       
    24     /**
       
    25      * @var LoaderInterface[] An array of LoaderInterface objects
       
    26      */
       
    27     private $loaders;
       
    28 
       
    29     /**
       
    30      * Constructor.
       
    31      *
       
    32      * @param LoaderInterface[] $loaders An array of loaders
       
    33      */
       
    34     public function __construct(array $loaders = array())
       
    35     {
       
    36         $this->loaders = array();
       
    37         foreach ($loaders as $loader) {
       
    38             $this->addLoader($loader);
       
    39         }
       
    40     }
       
    41 
       
    42     /**
       
    43      * Returns a loader able to load the resource.
       
    44      *
       
    45      * @param mixed  $resource A resource
       
    46      * @param string $type     The resource type
       
    47      *
       
    48      * @return LoaderInterface|false A LoaderInterface instance
       
    49      */
       
    50     public function resolve($resource, $type = null)
       
    51     {
       
    52         foreach ($this->loaders as $loader) {
       
    53             if ($loader->supports($resource, $type)) {
       
    54                 return $loader;
       
    55             }
       
    56         }
       
    57 
       
    58         return false;
       
    59     }
       
    60 
       
    61     /**
       
    62      * Adds a loader.
       
    63      *
       
    64      * @param LoaderInterface $loader A LoaderInterface instance
       
    65      */
       
    66     public function addLoader(LoaderInterface $loader)
       
    67     {
       
    68         $this->loaders[] = $loader;
       
    69         $loader->setResolver($this);
       
    70     }
       
    71 
       
    72     /**
       
    73      * Returns the registered loaders.
       
    74      *
       
    75      * @return LoaderInterface[] An array of LoaderInterface instances
       
    76      */
       
    77     public function getLoaders()
       
    78     {
       
    79         return $this->loaders;
       
    80     }
       
    81 }