1 | <?php |
||
28 | class FormatterOptions |
||
29 | { |
||
30 | /** var array */ |
||
31 | protected $configurationData = []; |
||
32 | /** var array */ |
||
33 | protected $options = []; |
||
34 | /** var InputInterface */ |
||
35 | protected $input; |
||
36 | |||
37 | const FORMAT = 'format'; |
||
38 | const DEFAULT_FORMAT = 'default-format'; |
||
39 | const TABLE_STYLE = 'table-style'; |
||
40 | const LIST_ORIENTATION = 'list-orientation'; |
||
41 | const FIELDS = 'fields'; |
||
42 | const FIELD = 'field'; |
||
43 | const INCLUDE_FIELD_LABELS = 'include-field-labels'; |
||
44 | const ROW_LABELS = 'row-labels'; |
||
45 | const FIELD_LABELS = 'field-labels'; |
||
46 | const DEFAULT_FIELDS = 'default-fields'; |
||
47 | const DEFAULT_STRING_FIELD = 'default-string-field'; |
||
48 | const DELIMITER = 'delimiter'; |
||
49 | const LIST_DELIMITER = 'list-delimiter'; |
||
50 | const TERMINAL_WIDTH = 'width'; |
||
51 | |||
52 | /** |
||
53 | * Create a new FormatterOptions with the configuration data and the |
||
54 | * user-specified options for this request. |
||
55 | * |
||
56 | * @see FormatterOptions::setInput() |
||
57 | * @param array $configurationData |
||
58 | * @param array $options |
||
59 | */ |
||
60 | public function __construct($configurationData = [], $options = []) |
||
65 | |||
66 | /** |
||
67 | * Create a new FormatterOptions object with new configuration data (provided), |
||
68 | * and the same options data as this instance. |
||
69 | * |
||
70 | * @param array $configurationData |
||
71 | * @return FormatterOptions |
||
72 | */ |
||
73 | public function override($configurationData) |
||
81 | |||
82 | public function setTableStyle($style) |
||
86 | |||
87 | public function setDelimiter($delimiter) |
||
91 | |||
92 | public function setListDelimiter($listDelimiter) |
||
96 | |||
97 | |||
98 | |||
99 | public function setIncludeFieldLables($includFieldLables) |
||
103 | |||
104 | public function setListOrientation($listOrientation) |
||
108 | |||
109 | public function setRowLabels($rowLabels) |
||
113 | |||
114 | public function setDefaultFields($fields) |
||
118 | |||
119 | public function setFieldLabels($fieldLabels) |
||
123 | |||
124 | public function setDefaultStringField($defaultStringField) |
||
128 | |||
129 | public function setWidth($width) |
||
133 | |||
134 | /** |
||
135 | * Get a formatter option |
||
136 | * |
||
137 | * @param string $key |
||
138 | * @param array $defaults |
||
139 | * @param mixed $default |
||
140 | * @return mixed |
||
141 | */ |
||
142 | public function get($key, $defaults = [], $default = false) |
||
147 | |||
148 | /** |
||
149 | * Return the XmlSchema to use with --format=xml for data types that support |
||
150 | * that. This is used when an array needs to be converted into xml. |
||
151 | * |
||
152 | * @return XmlSchema |
||
153 | */ |
||
154 | public function getXmlSchema() |
||
158 | |||
159 | /** |
||
160 | * Determine the format that was requested by the caller. |
||
161 | * |
||
162 | * @param array $defaults |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getFormat($defaults = []) |
||
169 | |||
170 | /** |
||
171 | * Look up a key, and return its raw value. |
||
172 | * |
||
173 | * @param string $key |
||
174 | * @param array $defaults |
||
175 | * @param mixed $default |
||
176 | * @return mixed |
||
177 | */ |
||
178 | protected function fetch($key, $defaults = [], $default = false) |
||
184 | |||
185 | /** |
||
186 | * Reduce provided defaults to the single item identified by '$key', |
||
187 | * if it exists, or an empty array otherwise. |
||
188 | * |
||
189 | * @param string $key |
||
190 | * @param array $defaults |
||
191 | * @return array |
||
192 | */ |
||
193 | protected function defaultsForKey($key, $defaults, $default = false) |
||
200 | |||
201 | /** |
||
202 | * Look up all of the items associated with the provided defaults. |
||
203 | * |
||
204 | * @param array $defaults |
||
205 | * @return array |
||
206 | */ |
||
207 | protected function fetchRawValues($defaults = []) |
||
216 | |||
217 | /** |
||
218 | * Given the raw value for a specific key, do any type conversion |
||
219 | * (e.g. from a textual list to an array) needed for the data. |
||
220 | * |
||
221 | * @param string $key |
||
222 | * @param mixed $value |
||
223 | * @return mixed |
||
224 | */ |
||
225 | protected function parse($key, $value) |
||
233 | |||
234 | /** |
||
235 | * Convert from a textual list to an array |
||
236 | * |
||
237 | * @param string $value |
||
238 | * @return array |
||
239 | */ |
||
240 | public function parsePropertyList($value) |
||
244 | |||
245 | /** |
||
246 | * Given a specific key, return the class method name of the |
||
247 | * parsing method for data stored under this key. |
||
248 | * |
||
249 | * @param string $key |
||
250 | * @return string |
||
251 | */ |
||
252 | protected function getOptionFormat($key) |
||
263 | |||
264 | /** |
||
265 | * Change the configuration data for this formatter options object. |
||
266 | * |
||
267 | * @param array $configurationData |
||
268 | * @return FormatterOptions |
||
269 | */ |
||
270 | public function setConfigurationData($configurationData) |
||
275 | |||
276 | /** |
||
277 | * Change one configuration value for this formatter option. |
||
278 | * |
||
279 | * @param string $key |
||
280 | * @param mixed $value |
||
281 | * @return FormetterOptions |
||
282 | */ |
||
283 | protected function setConfigurationValue($key, $value) |
||
288 | |||
289 | /** |
||
290 | * Change one configuration value for this formatter option, but only |
||
291 | * if it does not already have a value set. |
||
292 | * |
||
293 | * @param string $key |
||
294 | * @param mixed $value |
||
295 | * @return FormetterOptions |
||
296 | */ |
||
297 | public function setConfigurationDefault($key, $value) |
||
304 | |||
305 | /** |
||
306 | * Return a reference to the configuration data for this object. |
||
307 | * |
||
308 | * @return array |
||
309 | */ |
||
310 | public function getConfigurationData() |
||
314 | |||
315 | /** |
||
316 | * Set all of the options that were specified by the user for this request. |
||
317 | * |
||
318 | * @param array $options |
||
319 | * @return FormatterOptions |
||
320 | */ |
||
321 | public function setOptions($options) |
||
326 | |||
327 | /** |
||
328 | * Change one option value specified by the user for this request. |
||
329 | * |
||
330 | * @param string $key |
||
331 | * @param mixed $value |
||
332 | * @return FormatterOptions |
||
333 | */ |
||
334 | public function setOption($key, $value) |
||
339 | |||
340 | /** |
||
341 | * Return a reference to the user-specified options for this request. |
||
342 | * |
||
343 | * @return array |
||
344 | */ |
||
345 | public function getOptions() |
||
349 | |||
350 | /** |
||
351 | * Provide a Symfony Console InputInterface containing the user-specified |
||
352 | * options for this request. |
||
353 | * |
||
354 | * @param InputInterface $input |
||
355 | * @return type |
||
356 | */ |
||
357 | public function setInput(InputInterface $input) |
||
361 | |||
362 | /** |
||
363 | * Return all of the options from the provided $defaults array that |
||
364 | * exist in our InputInterface object. |
||
365 | * |
||
366 | * @param array $defaults |
||
367 | * @return array |
||
368 | */ |
||
369 | public function getInputOptions($defaults) |
||
385 | } |
||
386 |