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 | private $_env; |
||
124 | |||
125 | /** |
||
126 | * Assign the env to each component, module or application that defined inside the callback. |
||
127 | * |
||
128 | * Callback function has one parameter with the current {{luya\Config}} object. |
||
129 | * |
||
130 | * @param string $env The environment to assigne inside the callback. |
||
131 | * @param callable $callback function(\luya\Config $config) |
||
132 | * @return $this |
||
133 | */ |
||
134 | public function env($env, callable $callback) |
||
146 | |||
147 | /** |
||
148 | * register application level config |
||
149 | * |
||
150 | * @param array $config The array to configure |
||
151 | * @return ConfigDefinition |
||
152 | */ |
||
153 | public function application(array $config) |
||
157 | |||
158 | /** |
||
159 | * Register one or more bootstrap entries into the bootstrap section. |
||
160 | * |
||
161 | * @param array $config An array with bootstrap entries, its common to use the module name |
||
162 | * @return ConfigDefinition |
||
163 | */ |
||
164 | public function bootstrap(array $config) |
||
168 | |||
169 | /** |
||
170 | * Register a module. |
||
171 | * |
||
172 | * @param string $id The module identifier. |
||
173 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
174 | * @return ConfigDefinition |
||
175 | */ |
||
176 | public function module($id, $config) |
||
180 | |||
181 | /** |
||
182 | * Register a component |
||
183 | * |
||
184 | * @param string $id The id of the component |
||
185 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
186 | * @param string $runtime The runtime for the component: all, web or console |
||
187 | * @return ConfigDefinition |
||
188 | */ |
||
189 | public function component($id, $config, $runtime = self::RUNTIME_ALL) |
||
193 | |||
194 | /** |
||
195 | * Register a web runtime component. |
||
196 | * |
||
197 | * @param string $id The id of the component |
||
198 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
199 | * @return ConfigDefinition |
||
200 | */ |
||
201 | public function webComponent($id, $config) |
||
205 | |||
206 | /** |
||
207 | * Register a console runtime component. |
||
208 | * |
||
209 | * @param string $id The id of the component |
||
210 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
211 | * @return ConfigDefinition |
||
212 | */ |
||
213 | public function consoleComponent($id, $config) |
||
217 | |||
218 | private $_definitions = []; |
||
219 | |||
220 | /** |
||
221 | * Add a defintion into the defintions bag. |
||
222 | * |
||
223 | * @param ConfigDefinition $definition |
||
224 | * @return ConfigDefinition |
||
225 | */ |
||
226 | private function addDefinition(ConfigDefinition $definition) |
||
236 | |||
237 | private $_isCliRuntime; |
||
238 | |||
239 | /** |
||
240 | * Whether runtime is cli or not |
||
241 | * |
||
242 | * @return boolean |
||
243 | */ |
||
244 | public function isCliRuntime() |
||
252 | |||
253 | /** |
||
254 | * Setter method for runtime. |
||
255 | * |
||
256 | * > This method is mainly used for unit testing. |
||
257 | * |
||
258 | * @param boolean $value |
||
259 | */ |
||
260 | public function setCliRuntime($value) |
||
264 | |||
265 | /** |
||
266 | * Export the given configuration as array for certain envs. |
||
267 | * |
||
268 | * @param array $envs A list of environments to export. if nothing is given all enviroments will be returned. |
||
269 | * @return array The configuration array |
||
270 | */ |
||
271 | public function toArray(array $envs = []) |
||
292 | |||
293 | /** |
||
294 | * Append a given defintion int othe config |
||
295 | * |
||
296 | * @param array $config |
||
297 | * @param ConfigDefinition $definition |
||
298 | */ |
||
299 | private function appendConfig(&$config, ConfigDefinition $definition) |
||
324 | |||
325 | /** |
||
326 | * Add a array key based component defintion. |
||
327 | * |
||
328 | * @param array $config |
||
329 | * @param ConfigDefinition $definition |
||
330 | * @param string $section |
||
331 | */ |
||
332 | private function handleKeyBaseMerge(&$config, ConfigDefinition $definition, $section) |
||
346 | } |
||
347 |