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 LoaderResolverInterface A LoaderResolverInterface instance
29: */
30: public function getResolver()
31: {
32: return $this->resolver;
33: }
34:
35: /**
36: * Sets the loader resolver.
37: *
38: * @param LoaderResolverInterface $resolver A LoaderResolverInterface instance
39: */
40: public function setResolver(LoaderResolverInterface $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: * @return mixed
52: */
53: public function import($resource, $type = null)
54: {
55: return $this->resolve($resource)->load($resource, $type);
56: }
57:
58: /**
59: * Finds a loader able to load an imported resource.
60: *
61: * @param mixed $resource A Resource
62: * @param string $type The resource type
63: *
64: * @return LoaderInterface A LoaderInterface instance
65: *
66: * @throws FileLoaderLoadException if no loader is found
67: */
68: public function resolve($resource, $type = null)
69: {
70: if ($this->supports($resource, $type)) {
71: return $this;
72: }
73:
74: $loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type);
75:
76: if (false === $loader) {
77: throw new FileLoaderLoadException($resource);
78: }
79:
80: return $loader;
81: }
82: }
83: