Version 1
[yaffs-website] / vendor / symfony / config / Loader / LoaderResolver.php
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 = array();
28
29     /**
30      * Constructor.
31      *
32      * @param LoaderInterface[] $loaders An array of loaders
33      */
34     public function __construct(array $loaders = array())
35     {
36         foreach ($loaders as $loader) {
37             $this->addLoader($loader);
38         }
39     }
40
41     /**
42      * {@inheritdoc}
43      */
44     public function resolve($resource, $type = null)
45     {
46         foreach ($this->loaders as $loader) {
47             if ($loader->supports($resource, $type)) {
48                 return $loader;
49             }
50         }
51
52         return false;
53     }
54
55     /**
56      * Adds a loader.
57      *
58      * @param LoaderInterface $loader A LoaderInterface instance
59      */
60     public function addLoader(LoaderInterface $loader)
61     {
62         $this->loaders[] = $loader;
63         $loader->setResolver($this);
64     }
65
66     /**
67      * Returns the registered loaders.
68      *
69      * @return LoaderInterface[] An array of LoaderInterface instances
70      */
71     public function getLoaders()
72     {
73         return $this->loaders;
74     }
75 }