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
|
|
|
/** |
29
|
|
|
* @var integer boostrap section group |
30
|
|
|
*/ |
31
|
|
|
const GROUP_BOOTSTRAPS = 4; |
32
|
|
|
|
33
|
|
|
private $_group; |
34
|
|
|
|
35
|
|
|
private $_key; |
36
|
|
|
|
37
|
|
|
private $_config = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Consturctor |
41
|
|
|
* |
42
|
|
|
* @param string $group |
43
|
|
|
* @param string $key |
44
|
|
|
* @param mixed $config |
45
|
|
|
*/ |
46
|
|
|
public function __construct($group, $key, $config) |
47
|
|
|
{ |
48
|
|
|
$this->_group = $group; |
49
|
|
|
$this->_key = $key; |
50
|
|
|
$this->_config = is_array($config) ? $config : ['class' => $config]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private $_env = Config::ENV_ALL; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Set env |
57
|
|
|
* |
58
|
|
|
* @param string $env |
59
|
|
|
* @return static |
60
|
|
|
*/ |
61
|
|
|
public function env($env) |
62
|
|
|
{ |
63
|
|
|
$this->_env = $env; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private $_runtime = Config::RUNTIME_ALL; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Set runtime |
72
|
|
|
* |
73
|
|
|
* @param string $runtime |
74
|
|
|
* @return static |
75
|
|
|
*/ |
76
|
|
|
public function runtime($runtime) |
77
|
|
|
{ |
78
|
|
|
$this->_runtime = $runtime; |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Set console runtime |
85
|
|
|
* |
86
|
|
|
* @return static |
87
|
|
|
*/ |
88
|
|
|
public function consoleRuntime() |
89
|
|
|
{ |
90
|
|
|
$this->_runtime = Config::RUNTIME_CONSOLE; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Set web runtime |
97
|
|
|
* |
98
|
|
|
* @return static |
99
|
|
|
*/ |
100
|
|
|
public function webRuntime() |
101
|
|
|
{ |
102
|
|
|
$this->_runtime = Config::RUNTIME_WEB; |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Getter method for group |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getGroup() |
113
|
|
|
{ |
114
|
|
|
return $this->_group; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Getter method for config key |
119
|
|
|
* |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function getKey() |
123
|
|
|
{ |
124
|
|
|
return $this->_key; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Getter method for config |
129
|
|
|
* |
130
|
|
|
* @return array |
131
|
|
|
*/ |
132
|
|
|
public function getConfig() |
133
|
|
|
{ |
134
|
|
|
return $this->_config; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Validate whether its given runtime or not |
139
|
|
|
* |
140
|
|
|
* @param string $runtime |
141
|
|
|
* @return boolean |
142
|
|
|
*/ |
143
|
|
|
public function validateRuntime($runtime) |
144
|
|
|
{ |
145
|
|
|
return $this->_runtime == $runtime; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Validate whether given env exsts or not. |
150
|
|
|
* |
151
|
|
|
* @param array $envs |
152
|
|
|
* @return boolean |
153
|
|
|
*/ |
154
|
|
|
public function validateEnvs(array $envs) |
155
|
|
|
{ |
156
|
|
|
return in_array($this->_env, $envs); |
157
|
|
|
} |
158
|
|
|
} |