1 | <?php |
||
66 | class Config |
||
67 | { |
||
68 | const ENV_ALL = 'all'; |
||
69 | |||
70 | const ENV_PROD = 'prod'; |
||
71 | |||
72 | const ENV_PREP = 'prep'; |
||
73 | |||
74 | const ENV_DEV = 'dev'; |
||
75 | |||
76 | const ENV_LOCAL = 'local'; |
||
77 | |||
78 | const RUNTIME_ALL = 0; |
||
79 | |||
80 | const RUNTIME_CONSOLE = 1; |
||
81 | |||
82 | const RUNTIME_WEB = 2; |
||
83 | |||
84 | /** |
||
85 | * Constructor |
||
86 | * |
||
87 | * @param string $id |
||
88 | * @param string $basePath |
||
89 | * @param array $applicationConfig |
||
90 | */ |
||
91 | public function __construct($id, $basePath, array $applicationConfig = []) |
||
98 | |||
99 | /** |
||
100 | * register application level config |
||
101 | * |
||
102 | * @param array $config The array to configure |
||
103 | * @return ConfigDefinition |
||
104 | */ |
||
105 | public function application(array $config) |
||
109 | |||
110 | /** |
||
111 | * Register a module. |
||
112 | * |
||
113 | * @param string $id The module identifier. |
||
114 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
115 | * @return ConfigDefinition |
||
116 | */ |
||
117 | public function module($id, $config) |
||
121 | |||
122 | /** |
||
123 | * Register a component |
||
124 | * |
||
125 | * @param string $id The id of the component |
||
126 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
127 | * @param string $runtime The runtime for the component: all, web or console |
||
128 | * @return ConfigDefinition |
||
129 | */ |
||
130 | public function component($id, $config, $runtime = self::RUNTIME_ALL) |
||
134 | |||
135 | /** |
||
136 | * Register a web runtime component. |
||
137 | * |
||
138 | * @param string $id The id of the component |
||
139 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
140 | * @return ConfigDefinition |
||
141 | */ |
||
142 | public function webComponent($id, $config) |
||
146 | |||
147 | /** |
||
148 | * Register a console runtime component. |
||
149 | * |
||
150 | * @param string $id The id of the component |
||
151 | * @param string|array $config The configuration for the given module. If a string is given this will be taken as `class` property. |
||
152 | * @return ConfigDefinition |
||
153 | */ |
||
154 | public function consoleComponent($id, $config) |
||
158 | |||
159 | private $_definitions = []; |
||
160 | |||
161 | /** |
||
162 | * Add a defintion into the defintions bag. |
||
163 | * |
||
164 | * @param ConfigDefinition $definition |
||
165 | * @return ConfigDefinition |
||
166 | */ |
||
167 | private function addDefinition(ConfigDefinition $definition) |
||
173 | |||
174 | private $_isCliRuntime; |
||
175 | |||
176 | /** |
||
177 | * Whether runtime is cli or not |
||
178 | * |
||
179 | * @return boolean |
||
180 | */ |
||
181 | public function isCliRuntime() |
||
189 | |||
190 | /** |
||
191 | * Setter method for runtime. |
||
192 | * |
||
193 | * > This method is mainly used for unit testing. |
||
194 | * |
||
195 | * @param boolean $value |
||
196 | */ |
||
197 | public function setCliRuntime($value) |
||
201 | |||
202 | /** |
||
203 | * Export the given configuration as array for certain envs. |
||
204 | * |
||
205 | * @param array $envs A list of environments to export. if nothing is given all enviroments will be returned. |
||
206 | * @return array The configuration array |
||
207 | */ |
||
208 | public function toArray(array $envs = []) |
||
230 | |||
231 | /** |
||
232 | * Append a given defintion int othe config |
||
233 | * |
||
234 | * @param array $config |
||
235 | * @param ConfigDefinition $definition |
||
236 | */ |
||
237 | private function appendConfig(&$config, ConfigDefinition $definition) |
||
254 | |||
255 | /** |
||
256 | * Add a array key based component defintion. |
||
257 | * |
||
258 | * @param array $config |
||
259 | * @param ConfigDefinition $definition |
||
260 | * @param string $section |
||
261 | */ |
||
262 | private function handleKeyBaseMerge(&$config, ConfigDefinition $definition, $section) |
||
274 | } |