Completed
Push — feature/EVO-7964_fundInfo-exte... ( eda009...805323 )
by Bastian
62:49
created

LoaderFactory::addLoaderDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
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
     * Adds a loader to the set of registered loaders.
26
     *
27
     * @param LoaderInterface $loader Loader definintion
28
     * @param string          $key    Indentifier to find the registered loader
29
     */
30
    public function addLoaderDefinition(LoaderInterface $loader, $key)
31
    {
32
        $this->loader[$key] = $loader;
33
    }
34
35
    /**
36
     * Provides the definition loader identified by the given key.
37
     *
38
     * @param string $key Name of the loader to be returned
39
     *
40
     * @return LoaderInterface|null
41
     */
42
    public function getLoaderDefinition($key)
43
    {
44
        if (array_key_exists($key, $this->loader)) {
45
            return $this->loader[$key];
46
        }
47
48
        return null;
49
    }
50
51
    /**
52
     * Provides a list of registered loaders
53
     *
54
     * @return array
55
     */
56
    public function getLoaderDefinitions()
57
    {
58
        return $this->loader;
59
    }
60
61
    /**
62
     * Provides
63
     *
64
     * @param string $source Information of what loader to be initiated.
65
     *
66
     * @return LoaderInterface
67
     *
68
     * @throws LoaderException
69
     */
70
    public function create($source)
71
    {
72
        if (array_key_exists($source, $this->loader)) {
73
            return $this->loader[$source];
74
        }
75
76
        throw new LoaderException('Expected Loader for source ('. $source .') does not exist.');
77
    }
78
}
79