1 | <?php |
||
91 | class Config |
||
92 | { |
||
93 | const ENV_ALL = 'all'; |
||
94 | |||
95 | const ENV_PROD = 'prod'; |
||
96 | |||
97 | const ENV_PREP = 'prep'; |
||
98 | |||
99 | const ENV_DEV = 'dev'; |
||
100 | |||
101 | const ENV_LOCAL = 'local'; |
||
102 | |||
103 | const RUNTIME_ALL = 0; |
||
104 | |||
105 | const RUNTIME_CONSOLE = 1; |
||
106 | |||
107 | const RUNTIME_WEB = 2; |
||
108 | |||
109 | /** |
||
110 | * Constructor |
||
111 | * |
||
112 | * @param string $id |
||
113 | * @param string $basePath |
||
114 | * @param array $applicationConfig |
||
115 | */ |
||
116 | public function __construct($id, $basePath, array $applicationConfig = []) |
||
122 | |||
123 | /** |
||
124 | * register application level config |
||
125 | * |
||
126 | * @param array $config The array to configure |
||
127 | * @return ConfigDefinition |
||
128 | */ |
||
129 | public function application(array $config) |
||
133 | |||
134 | /** |
||
135 | * Register a module. |
||
136 | * |
||
137 | * @param string $id The module identifier. |
||
138 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
139 | * @return ConfigDefinition |
||
140 | */ |
||
141 | public function module($id, $config) |
||
145 | |||
146 | /** |
||
147 | * Register a component |
||
148 | * |
||
149 | * @param string $id The id of the component |
||
150 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
151 | * @param string $runtime The runtime for the component: all, web or console |
||
152 | * @return ConfigDefinition |
||
153 | */ |
||
154 | public function component($id, $config, $runtime = self::RUNTIME_ALL) |
||
158 | |||
159 | /** |
||
160 | * Register a web runtime component. |
||
161 | * |
||
162 | * @param string $id The id of the component |
||
163 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
164 | * @return ConfigDefinition |
||
165 | */ |
||
166 | public function webComponent($id, $config) |
||
170 | |||
171 | /** |
||
172 | * Register a console runtime component. |
||
173 | * |
||
174 | * @param string $id The id of the component |
||
175 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
176 | * @return ConfigDefinition |
||
177 | */ |
||
178 | public function consoleComponent($id, $config) |
||
182 | |||
183 | private $_definitions = []; |
||
184 | |||
185 | /** |
||
186 | * Add a defintion into the defintions bag. |
||
187 | * |
||
188 | * @param ConfigDefinition $definition |
||
189 | * @return ConfigDefinition |
||
190 | */ |
||
191 | private function addDefinition(ConfigDefinition $definition) |
||
197 | |||
198 | private $_isCliRuntime; |
||
199 | |||
200 | /** |
||
201 | * Whether runtime is cli or not |
||
202 | * |
||
203 | * @return boolean |
||
204 | */ |
||
205 | public function isCliRuntime() |
||
213 | |||
214 | /** |
||
215 | * Setter method for runtime. |
||
216 | * |
||
217 | * > This method is mainly used for unit testing. |
||
218 | * |
||
219 | * @param boolean $value |
||
220 | */ |
||
221 | public function setCliRuntime($value) |
||
225 | |||
226 | /** |
||
227 | * Export the given configuration as array for certain envs. |
||
228 | * |
||
229 | * @param array $envs A list of environments to export. if nothing is given all enviroments will be returned. |
||
230 | * @return array The configuration array |
||
231 | */ |
||
232 | public function toArray(array $envs = []) |
||
253 | |||
254 | /** |
||
255 | * Append a given defintion int othe config |
||
256 | * |
||
257 | * @param array $config |
||
258 | * @param ConfigDefinition $definition |
||
259 | */ |
||
260 | private function appendConfig(&$config, ConfigDefinition $definition) |
||
277 | |||
278 | /** |
||
279 | * Add a array key based component defintion. |
||
280 | * |
||
281 | * @param array $config |
||
282 | * @param ConfigDefinition $definition |
||
283 | * @param string $section |
||
284 | */ |
||
285 | private function handleKeyBaseMerge(&$config, ConfigDefinition $definition, $section) |
||
299 | } |