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