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 one or more bootstrap entries into the bootstrap section. |
||
136 | * |
||
137 | * @param array $config An array with bootstrap entries, its common to use the module name |
||
138 | * @return ConfigDefinition |
||
139 | */ |
||
140 | public function bootstrap(array $config) |
||
144 | |||
145 | /** |
||
146 | * Register a module. |
||
147 | * |
||
148 | * @param string $id The module identifier. |
||
149 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
150 | * @return ConfigDefinition |
||
151 | */ |
||
152 | public function module($id, $config) |
||
156 | |||
157 | /** |
||
158 | * Register a component |
||
159 | * |
||
160 | * @param string $id The id of the component |
||
161 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
162 | * @param string $runtime The runtime for the component: all, web or console |
||
163 | * @return ConfigDefinition |
||
164 | */ |
||
165 | public function component($id, $config, $runtime = self::RUNTIME_ALL) |
||
169 | |||
170 | /** |
||
171 | * Register a web runtime component. |
||
172 | * |
||
173 | * @param string $id The id of the component |
||
174 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
175 | * @return ConfigDefinition |
||
176 | */ |
||
177 | public function webComponent($id, $config) |
||
181 | |||
182 | /** |
||
183 | * Register a console runtime component. |
||
184 | * |
||
185 | * @param string $id The id of the component |
||
186 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
187 | * @return ConfigDefinition |
||
188 | */ |
||
189 | public function consoleComponent($id, $config) |
||
193 | |||
194 | private $_definitions = []; |
||
195 | |||
196 | /** |
||
197 | * Add a defintion into the defintions bag. |
||
198 | * |
||
199 | * @param ConfigDefinition $definition |
||
200 | * @return ConfigDefinition |
||
201 | */ |
||
202 | private function addDefinition(ConfigDefinition $definition) |
||
208 | |||
209 | private $_isCliRuntime; |
||
210 | |||
211 | /** |
||
212 | * Whether runtime is cli or not |
||
213 | * |
||
214 | * @return boolean |
||
215 | */ |
||
216 | public function isCliRuntime() |
||
224 | |||
225 | /** |
||
226 | * Setter method for runtime. |
||
227 | * |
||
228 | * > This method is mainly used for unit testing. |
||
229 | * |
||
230 | * @param boolean $value |
||
231 | */ |
||
232 | public function setCliRuntime($value) |
||
236 | |||
237 | /** |
||
238 | * Export the given configuration as array for certain envs. |
||
239 | * |
||
240 | * @param array $envs A list of environments to export. if nothing is given all enviroments will be returned. |
||
241 | * @return array The configuration array |
||
242 | */ |
||
243 | public function toArray(array $envs = []) |
||
264 | |||
265 | /** |
||
266 | * Append a given defintion int othe config |
||
267 | * |
||
268 | * @param array $config |
||
269 | * @param ConfigDefinition $definition |
||
270 | */ |
||
271 | private function appendConfig(&$config, ConfigDefinition $definition) |
||
296 | |||
297 | /** |
||
298 | * Add a array key based component defintion. |
||
299 | * |
||
300 | * @param array $config |
||
301 | * @param ConfigDefinition $definition |
||
302 | * @param string $section |
||
303 | */ |
||
304 | private function handleKeyBaseMerge(&$config, ConfigDefinition $definition, $section) |
||
318 | } |