1 | <?php |
||
6 | class Config |
||
7 | { |
||
8 | const PROGRESS_BAR_AUTO_DISPLAY_INTERVAL = 'progress-delay'; |
||
9 | const DEFAULT_PROGRESS_DELAY = 2; |
||
10 | const SIMULATE = 'simulate'; |
||
11 | const INTERACTIVE = 'interactive'; |
||
12 | const DECORATED = 'decorated'; |
||
13 | |||
14 | /** |
||
15 | * @var Data |
||
16 | */ |
||
17 | protected $config; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $defaults; |
||
23 | |||
24 | /** |
||
25 | * Create a new configuration object, and initialize it with |
||
26 | * the provided nested array containing configuration data. |
||
27 | */ |
||
28 | public function __construct(array $data = null) |
||
33 | |||
34 | /** |
||
35 | * Determine if a non-default config value exists. |
||
36 | */ |
||
37 | public function has($key) |
||
41 | |||
42 | /** |
||
43 | * Fetch a configuration value |
||
44 | * |
||
45 | * @param string $key Which config item to look up |
||
46 | * @param string|null $defaultOverride Override usual default value with a different default. Deprecated; provide defaults to the config processor instead. |
||
47 | * |
||
48 | * @return mixed |
||
49 | */ |
||
50 | public function get($key, $defaultOverride = null) |
||
57 | |||
58 | /** |
||
59 | * Fetch an option value from a given key, or, if that specific key does |
||
60 | * not contain a value, then consult various fallback options until a |
||
61 | * value is found. |
||
62 | * |
||
63 | * Given the following inputs: |
||
64 | * - $prefix = "command." |
||
65 | * - $group = "foo.bar.baz" |
||
66 | * - $postfix = ".options." |
||
67 | * This method will then consider, in order: |
||
68 | * - command.foo.bar.baz.options |
||
69 | * - command.foo.bar.options |
||
70 | * - command.foo.options |
||
71 | * If any of these contain an option for "$key", then return its value. |
||
72 | */ |
||
73 | public function getWithFallback($key, $group, $prefix = '', $postfix = '.') |
||
88 | |||
89 | /** |
||
90 | * Works like 'getWithFallback', but merges results from all applicable |
||
91 | * groups. Settings from most specific group take precedence. |
||
92 | */ |
||
93 | public function getWithMerge($key, $group, $prefix = '', $postfix = '.') |
||
111 | |||
112 | /** |
||
113 | * Set a config value |
||
114 | * |
||
115 | * @param string $key |
||
116 | * @param mixed $value |
||
117 | * |
||
118 | * @return $this |
||
119 | */ |
||
120 | public function set($key, $value) |
||
125 | |||
126 | /** |
||
127 | * Import configuration from the provided nexted array, replacing whatever |
||
128 | * was here previously. No processing is done on the provided data. |
||
129 | * |
||
130 | * @param array $data |
||
131 | * @return Config |
||
132 | */ |
||
133 | public function import($data) |
||
141 | |||
142 | /** |
||
143 | * Export all configuration as a nested array. |
||
144 | */ |
||
145 | public function export() |
||
149 | |||
150 | /** |
||
151 | * Given an object that contains configuration methods, inject any |
||
152 | * configuration found in the configuration file. |
||
153 | * |
||
154 | * The proper use for this method is to call setter methods of the |
||
155 | * provided object. Using configuration to call methods that do work |
||
156 | * is an abuse of this mechanism. |
||
157 | * |
||
158 | * TODO: We could use reflection to test to see if the return type |
||
159 | * of the provided object is a reference to the object itself. All |
||
160 | * setter methods should do this. This test is insufficient to guarentee |
||
161 | * that the method is valid, but it would catch almost every misuse. |
||
162 | */ |
||
163 | public function applyConfiguration($object, $configurationKey, $group = '', $prefix = '', $postfix = '') |
||
178 | |||
179 | /** |
||
180 | * Return an associative array containing all of the global configuration |
||
181 | * options and their default values. |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | public function getGlobalOptionDefaultValues() |
||
195 | |||
196 | /** |
||
197 | * Return the default value for a given configuration item. |
||
198 | * |
||
199 | * @param string $key |
||
200 | * |
||
201 | * @return mixed |
||
202 | */ |
||
203 | public function hasDefault($key) |
||
207 | |||
208 | /** |
||
209 | * Return the default value for a given configuration item. |
||
210 | * |
||
211 | * @param string $key |
||
212 | * @param mixed $defaultOverride |
||
213 | * |
||
214 | * @return mixed |
||
215 | */ |
||
216 | public function getDefault($key, $defaultOverride = null) |
||
220 | |||
221 | /** |
||
222 | * Set the default value for a configuration setting. This allows us to |
||
223 | * set defaults either before or after more specific configuration values |
||
224 | * are loaded. Keeping defaults separate from current settings also |
||
225 | * allows us to determine when a setting has been overridden. |
||
226 | * |
||
227 | * @param string $key |
||
228 | * @param string $value |
||
229 | */ |
||
230 | public function setDefault($key, $value) |
||
235 | |||
236 | /** |
||
237 | * @return bool |
||
238 | */ |
||
239 | public function isSimulated() |
||
243 | |||
244 | /** |
||
245 | * @param bool $simulated |
||
246 | * |
||
247 | * @return $this |
||
248 | */ |
||
249 | public function setSimulated($simulated = true) |
||
253 | |||
254 | /** |
||
255 | * @return bool |
||
256 | */ |
||
257 | public function isInteractive() |
||
261 | |||
262 | /** |
||
263 | * @param bool $simulated |
||
|
|||
264 | * |
||
265 | * @return $this |
||
266 | */ |
||
267 | public function setInteractive($interactive = true) |
||
271 | |||
272 | /** |
||
273 | * @return bool |
||
274 | */ |
||
275 | public function isDecorated() |
||
279 | |||
280 | /** |
||
281 | * @param bool $decorated |
||
282 | * |
||
283 | * @return $this |
||
284 | */ |
||
285 | public function setDecorated($decorated = true) |
||
289 | |||
290 | /** |
||
291 | * @param int $interval |
||
292 | * |
||
293 | * @return $this |
||
294 | */ |
||
295 | public function setProgressBarAutoDisplayInterval($interval) |
||
299 | } |
||
300 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.