Completed
Push — feature/EVO-7964_fundInfo-exte... ( 142d3d...cf9459 )
by Bastian
08:28 queued 08:21
created

LoaderFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * LoaderFactory
4
 */
5
6
namespace Graviton\ProxyBundle\Definition\Loader;
7
8
use Graviton\ProxyBundle\Exception\LoaderException;
9
10
/**
11
 * Class LoaderFactory
12
 *
13
 * @package Graviton\ProxyBundle\Definition\Loader
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class LoaderFactory
19
{
20
    /** @var array  */
21
    private $loader;
22
23
24
    /**
25
     * LoaderFactory constructor.
26
     *
27
     * @param array $loader The set of definition loaders available.
28
     */
29
    public function __construct(array $loader)
30
    {
31
        $this->loader = $loader;
32
    }
33
34
    /**
35
     * Provides a list of registered loaders
36
     *
37
     * @return array
38
     */
39
    public function getLoaderDefinitions()
40
    {
41
        return $this->loader;
42
    }
43
44
    /**
45
     * Provides
46
     *
47
     * @param string $source Information of what loader to be initiated.
48
     *
49
     * @return LoaderInterface
50
     *
51
     * @throws LoaderException
52
     */
53
    public function create($source)
54
    {
55
        if (array_key_exists($source, $this->loader)) {
56
            return $this->loader[$source];
57
        }
58
59
        throw new LoaderException('Expected Loader for source ('. $source .') does not exist.');
60
    }
61
}
62