Completed
Push — master ( f72a4b...188ca1 )
by Pavel
04:06
created

Loader::resolve()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.3731

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 5
cts 7
cp 0.7143
rs 9.2
cc 4
eloc 7
nc 5
nop 2
crap 4.3731
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: batanov.pavel
5
 * Date: 16.02.2016
6
 * Time: 9:20
7
 */
8
9
namespace Bankiru\Api\Rpc\Routing\Loader;
10
11
12
use Bankiru\Api\Rpc\Routing\LoaderInterface;
13
use Bankiru\Api\Rpc\Routing\LoaderResolverInterface;
14
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)
29
    {
30
        return $this->resolve($resource, $type)->load($resource, $type);
31
    }
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()
58
    {
59
        return $this->resolver;
60
    }
61
62
    /** {@inheritdoc} */
63 8
    public function setResolver($resolver)
64
    {
65 8
        $this->resolver = $resolver;
66 8
    }
67
}
68