Configuration   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 91
wmc 8
lcom 1
cbo 4
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A raw() 0 8 2
A prepend() 0 6 1
A append() 0 6 1
A processConfiguration() 0 12 2
1
<?php
2
/*
3
 * This file is part of the Borobudur-Config 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\Config;
12
13
/**
14
 * @author      Iqbal Maulana <[email protected]>
15
 * @created     8/11/15
16
 */
17
class Configuration
18
{
19
    /**
20
     * @var array
21
     */
22
    private $configs = array();
23
24
    /**
25
     * @var ConfigDefinitionInterface[]
26
     */
27
    private $definitions = array();
28
29
    /**
30
     * Get processed configuration by name.
31
     *
32
     * @param string $name
33
     *
34
     * @return array
35
     */
36
    public function get($name)
37
    {
38
        if (isset($this->configs[$name])) {
39
            return ConfigParser::parseConfiguration($this->definitions[$name], $this->configs[$name]);
40
        }
41
42
        return array();
43
    }
44
45
    /**
46
     * Get unprocessed configuration by name.
47
     *
48
     * @param string $name
49
     *
50
     * @return array
51
     */
52
    public function raw($name)
53
    {
54
        if (isset($this->configs[$name])) {
55
            return $this->configs[$name];
56
        }
57
58
        return array();
59
    }
60
61
    /**
62
     * Prepend configuration with config definition.
63
     *
64
     * @param ConfigDefinitionInterface $definition
65
     * @param array                     $configs
66
     */
67
    public function prepend(ConfigDefinitionInterface $definition, array $configs)
68
    {
69
        $configs = $this->processConfiguration($definition, $configs);
70
        $name = $definition->getConfigTreeBuilder()->getNode()->getName();
71
        array_unshift($this->configs[$name], $configs);
72
    }
73
74
    /**
75
     * Append configuration with config definition.
76
     *
77
     * @param ConfigDefinitionInterface $definition
78
     * @param array                     $configs
79
     */
80
    public function append(ConfigDefinitionInterface $definition, array $configs)
81
    {
82
        $configs = $this->processConfiguration($definition, $configs);
83
        $name = $definition->getConfigTreeBuilder()->getNode()->getName();
84
        array_push($this->configs[$name], $configs);
85
    }
86
87
    /**
88
     * Process configuration from definition.
89
     *
90
     * @param ConfigDefinitionInterface $definition
91
     * @param array                     $configs
92
     *
93
     * @return array
94
     */
95
    private function processConfiguration(ConfigDefinitionInterface $definition, array $configs)
96
    {
97
        $configs = ConfigParser::parseConfiguration($definition, $configs);
98
        $name = $definition->getConfigTreeBuilder()->getNode()->getName();
99
100
        if (!isset($this->configs[$name])) {
101
            $this->configs[$name] = array();
102
            $this->definitions[$name] = $definition;
103
        }
104
105
        return $configs;
106
    }
107
}
108