vendor/symfony/src/Symfony/Component/Config/Loader/Loader.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 use Symfony\Component\Config\Exception\FileLoaderLoadException;
       
    15 
       
    16 /**
       
    17  * Loader is the abstract class used by all built-in loaders.
       
    18  *
       
    19  * @author Fabien Potencier <fabien@symfony.com>
       
    20  */
       
    21 abstract class Loader implements LoaderInterface
       
    22 {
       
    23     protected $resolver;
       
    24 
       
    25     /**
       
    26      * Gets the loader resolver.
       
    27      *
       
    28      * @return LoaderResolver A LoaderResolver instance
       
    29      */
       
    30     public function getResolver()
       
    31     {
       
    32         return $this->resolver;
       
    33     }
       
    34 
       
    35     /**
       
    36      * Sets the loader resolver.
       
    37      *
       
    38      * @param LoaderResolver $resolver A LoaderResolver instance
       
    39      */
       
    40     public function setResolver(LoaderResolver $resolver)
       
    41     {
       
    42         $this->resolver = $resolver;
       
    43     }
       
    44 
       
    45     /**
       
    46      * Imports a resource.
       
    47      *
       
    48      * @param mixed  $resource A Resource
       
    49      * @param string $type     The resource type
       
    50      */
       
    51     public function import($resource, $type = null)
       
    52     {
       
    53         $this->resolve($resource)->load($resource, $type);
       
    54     }
       
    55 
       
    56     /**
       
    57      * Finds a loader able to load an imported resource.
       
    58      *
       
    59      * @param mixed  $resource A Resource
       
    60      * @param string $type     The resource type
       
    61      *
       
    62      * @return LoaderInterface A LoaderInterface instance
       
    63      *
       
    64      * @throws FileLoaderLoadException if no loader is found
       
    65      */
       
    66     public function resolve($resource, $type = null)
       
    67     {
       
    68         if ($this->supports($resource, $type)) {
       
    69             return $this;
       
    70         }
       
    71 
       
    72         $loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type);
       
    73 
       
    74         if (false === $loader) {
       
    75             throw new FileLoaderLoadException($resource);
       
    76         }
       
    77 
       
    78         return $loader;
       
    79     }
       
    80 }