Completed
Pull Request — master (#1952)
by Basil
02:18
created

ConfigDefinition::getKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace luya;
4
5
/**
6
 * Contains the defintion of a config element.
7
 * 
8
 * @author Basil Suter <[email protected]>
9
 * @since 1.0.21
10
 */
11
class ConfigDefinition
12
{
13
    /**
14
     * @var integer componenets group
15
     */
16
    const GROUP_COMPONENTS = 1;
17
18
    /**
19
     * @var integer modules group
20
     */
21
    const GROUP_MODULES = 2;
22
23
    /**
24
     * @var integer applications group
25
     */
26
    const GROUP_APPLICATIONS = 3;
27
28
    private $_group;
29
30
    private $_key;
31
32
    private $_config = [];
33
34
    /**
35
     * Consturctor
36
     *
37
     * @param string $group
38
     * @param string $key
39
     * @param mixed $config
40
     */
41
    public function __construct($group, $key, $config)
42
    {
43
        $this->_group = $group;
44
        $this->_key = $key;
45
        $this->_config = is_array($config) ? $config : ['class' => $config];
46
    }
47
48
    private $_env = Config::ENV_ALL;
49
50
    /**
51
     * Set env
52
     *
53
     * @param string $env
54
     * @return static
55
     */
56
    public function env($env)
57
    {
58
        $this->_env = $env;
59
60
        return $this;
61
    }
62
63
    private $_runtime = Config::RUNTIME_ALL;
64
65
    /**
66
     * Set runtime
67
     *
68
     * @param string $runtime
69
     * @return static
70
     */
71
    public function runtime($runtime)
72
    {
73
        $this->_runtime = $runtime;
74
75
        return $this;
76
    }
77
    
78
    /**
79
     * Set console runtime
80
     *
81
     * @return static
82
     */
83
    public function consoleRuntime()
84
    {
85
        $this->_runtime = Config::RUNTIME_CONSOLE;
86
87
        return $this;
88
    }
89
90
    /**
91
     * Set web runtime
92
     *
93
     * @return static
94
     */
95
    public function webRuntime()
96
    {
97
        $this->_runtime = Config::RUNTIME_WEB;
98
99
        return $this;
100
    }
101
102
    /**
103
     * Getter method for group
104
     *
105
     * @return string
106
     */
107
    public function getGroup()
108
    {
109
        return $this->_group;
110
    }
111
112
    /**
113
     * Getter method for config key
114
     *
115
     * @return string
116
     */
117
    public function getKey()
118
    {
119
        return $this->_key;
120
    }
121
122
    /**
123
     * Getter method for config
124
     *
125
     * @return array
126
     */
127
    public function getConfig()
128
    {
129
        return $this->_config;
130
    }
131
132
    /**
133
     * Validate whether its given runtime or not
134
     *
135
     * @param string $runtime
136
     * @return boolean
137
     */
138
    public function validateRuntime($runtime)
139
    {
140
        return $this->_runtime == $runtime;
141
    }
142
143
    /**
144
     * Validate whether given env exsts or not.
145
     *
146
     * @param array $envs
147
     * @return boolean
148
     */
149
    public function validateEnvs(array $envs)
150
    {
151
        return in_array($this->_env, $envs);
152
    }
153
}