| 1 | <?php |
||
| 15 | abstract class Loader implements LoaderInterface |
||
| 16 | { |
||
| 17 | /** @var LoaderResolverInterface */ |
||
| 18 | private $resolver; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Imports a resource. |
||
| 22 | * |
||
| 23 | * @param mixed $resource A resource |
||
| 24 | * @param string|null $type The resource type or null if unknown |
||
| 25 | * |
||
| 26 | * @return mixed |
||
| 27 | */ |
||
| 28 | public function import($resource, $type = null) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Finds a loader able to load an imported resource. |
||
| 35 | * |
||
| 36 | * @param mixed $resource A resource |
||
| 37 | * @param string|null $type The resource type or null if unknown |
||
| 38 | * |
||
| 39 | * @return LoaderInterface A LoaderInterface instance |
||
| 40 | */ |
||
| 41 | 8 | public function resolve($resource, $type = null) |
|
| 42 | { |
||
| 43 | 8 | if ($this->supports($resource, $type)) { |
|
| 44 | return $this; |
||
| 45 | } |
||
| 46 | |||
| 47 | 8 | $loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type); |
|
| 48 | |||
| 49 | 8 | if (false === $loader) { |
|
| 50 | throw new \OutOfBoundsException($resource); |
||
| 51 | } |
||
| 52 | |||
| 53 | 8 | return $loader; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** {@inheritdoc} */ |
||
| 57 | public function getResolver() |
||
| 61 | |||
| 62 | /** {@inheritdoc} */ |
||
| 63 | 8 | public function setResolver($resolver) |
|
| 67 | } |
||
| 68 |