BundleManager::add()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Borobudur-Kernel package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Kernel\Bundling;
12
13
use Borobudur\Kernel\Exception\RuntimeException;
14
15
/**
16
 * @author      Iqbal Maulana <[email protected]>
17
 * @created     8/17/15
18
 */
19
class BundleManager
20
{
21
    /**
22
     * @var array
23
     */
24
    private $bundles = array();
25
26
    /**
27
     * Add bundles.
28
     *
29
     * @param BundleInterface[] $bundles
30
     */
31
    public function add(array $bundles)
32
    {
33
        foreach($bundles as $bundle) {
34
            $this->set($bundle);
35
        }
36
    }
37
38
    /**
39
     * Set bundle.
40
     *
41
     * @param BundleInterface $bundle
42
     */
43
    public function set(BundleInterface $bundle) {
44
        $name = $bundle->getName();
45
        if (isset($this->bundles[$name])) {
46
            throw new RuntimeException(sprintf('Bundle with name "%s" already registered.', $name));
47
        }
48
49
        $this->bundles[$name] = $bundle;
50
    }
51
52
    /**
53
     * Get registered bundle by name.
54
     *
55
     * @param string $name
56
     *
57
     * @return BundleInterface|null
58
     */
59
    public function get($name)
60
    {
61
        if (isset($this->bundles[$name])) {
62
            return $this->bundles[$name];
63
        }
64
65
        return null;
66
    }
67
68
    /**
69
     * Get all bundles.
70
     *
71
     * @return BundleInterface[]
72
     */
73
    public function all()
74
    {
75
        return $this->bundles;
76
    }
77
}
78