Completed
Push — master ( 055f1b...f72a4b )
by Pavel
52s
created

LoaderResolver::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2.032
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: batanov.pavel
5
 * Date: 16.02.2016
6
 * Time: 8:49
7
 */
8
9
namespace Bankiru\Api\Rpc\Routing;
10
11
12
class LoaderResolver implements LoaderResolverInterface
13
{
14
    /**
15
     * @var LoaderInterface[] An array of LoaderInterface objects
16
     */
17
    private $loaders = array();
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param LoaderInterface[] $loaders An array of loaders
23
     */
24 8
    public function __construct(array $loaders = array())
25
    {
26 8
        foreach ($loaders as $loader) {
27
            $this->addLoader($loader);
28 8
        }
29 8
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 8
    public function resolve($resource, $type = null)
35
    {
36 8
        foreach ($this->loaders as $loader) {
37 8
            if ($loader->supports($resource, $type)) {
38 8
                return $loader;
39
            }
40
        }
41
42
        return false;
43
    }
44
45
    /**
46
     * Adds a loader.
47
     *
48
     * @param LoaderInterface $loader A LoaderInterface instance
49
     */
50 8
    public function addLoader(LoaderInterface $loader)
51
    {
52 8
        $this->loaders[] = $loader;
53 8
    }
54
55
    /**
56
     * Returns the registered loaders.
57
     *
58
     * @return LoaderInterface[] An array of LoaderInterface instances
59
     */
60
    public function getLoaders()
61
    {
62
        return $this->loaders;
63
    }
64
}
65