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 | |||
50 | /** |
||
51 | * Create a new FormatterOptions with the configuration data and the |
||
52 | * user-specified options for this request. |
||
53 | * |
||
54 | * @see FormatterOptions::setInput() |
||
55 | * @param array $configurationData |
||
56 | * @param array $options |
||
57 | */ |
||
58 | public function __construct($configurationData = [], $options = []) |
||
63 | |||
64 | /** |
||
65 | * Create a new FormatterOptions object with new configuration data (provided), |
||
66 | * and the same options data as this instance. |
||
67 | * |
||
68 | * @param array $configurationData |
||
69 | * @return FormatterOptions |
||
70 | */ |
||
71 | public function override($configurationData) |
||
79 | |||
80 | /** |
||
81 | * Get a formatter option |
||
82 | * |
||
83 | * @param string $key |
||
84 | * @param array $defaults |
||
85 | * @param mixed $default |
||
86 | * @return mixed |
||
87 | */ |
||
88 | public function get($key, $defaults = [], $default = false) |
||
93 | |||
94 | /** |
||
95 | * Return the XmlSchema to use with --format=xml for data types that support |
||
96 | * that. This is used when an array needs to be converted into xml. |
||
97 | * |
||
98 | * @return XmlSchema |
||
99 | */ |
||
100 | public function getXmlSchema() |
||
104 | |||
105 | /** |
||
106 | * Determine the format that was requested by the caller. |
||
107 | * |
||
108 | * @param array $defaults |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getFormat($defaults = []) |
||
115 | |||
116 | /** |
||
117 | * Look up a key, and return its raw value. |
||
118 | * |
||
119 | * @param string $key |
||
120 | * @param array $defaults |
||
121 | * @param mixed $default |
||
122 | * @return mixed |
||
123 | */ |
||
124 | protected function fetch($key, $defaults = [], $default = false) |
||
130 | |||
131 | /** |
||
132 | * Reduce provided defaults to the single item identified by '$key', |
||
133 | * if it exists, or an empty array otherwise. |
||
134 | * |
||
135 | * @param string $key |
||
136 | * @param array $defaults |
||
137 | * @return array |
||
138 | */ |
||
139 | protected function defaultsForKey($key, $defaults, $default = false) |
||
146 | |||
147 | /** |
||
148 | * Look up all of the items associated with the provided defaults. |
||
149 | * |
||
150 | * @param array $defaults |
||
151 | * @return array |
||
152 | */ |
||
153 | protected function fetchRawValues($defaults = []) |
||
162 | |||
163 | /** |
||
164 | * Given the raw value for a specific key, do any type conversion |
||
165 | * (e.g. from a textual list to an array) needed for the data. |
||
166 | * |
||
167 | * @param string $key |
||
168 | * @param mixed $value |
||
169 | * @return mixed |
||
170 | */ |
||
171 | protected function parse($key, $value) |
||
179 | |||
180 | /** |
||
181 | * Convert from a textual list to an array |
||
182 | * |
||
183 | * @param string $value |
||
184 | * @return array |
||
185 | */ |
||
186 | public function parsePropertyList($value) |
||
190 | |||
191 | /** |
||
192 | * Given a specific key, return the class method name of the |
||
193 | * parsing method for data stored under this key. |
||
194 | * |
||
195 | * @param string $key |
||
196 | * @return string |
||
197 | */ |
||
198 | protected function getOptionFormat($key) |
||
209 | |||
210 | /** |
||
211 | * Change the configuration data for this formatter options object. |
||
212 | * |
||
213 | * @param array $configurationData |
||
214 | * @return FormatterOptions |
||
215 | */ |
||
216 | public function setConfigurationData($configurationData) |
||
221 | |||
222 | /** |
||
223 | * Change one configuration value for this formatter option. |
||
224 | * |
||
225 | * @param string $key |
||
226 | * @param mixed $value |
||
227 | * @return FormetterOptions |
||
228 | */ |
||
229 | protected function setConfigurationValue($key, $value) |
||
234 | |||
235 | /** |
||
236 | * Change one configuration value for this formatter option, but only |
||
237 | * if it does not already have a value set. |
||
238 | * |
||
239 | * @param string $key |
||
240 | * @param mixed $value |
||
241 | * @return FormetterOptions |
||
242 | */ |
||
243 | public function setConfigurationDefault($key, $value) |
||
250 | |||
251 | /** |
||
252 | * Return a reference to the configuration data for this object. |
||
253 | * |
||
254 | * @return array |
||
255 | */ |
||
256 | public function getConfigurationData() |
||
260 | |||
261 | /** |
||
262 | * Set all of the options that were specified by the user for this request. |
||
263 | * |
||
264 | * @param array $options |
||
265 | * @return FormatterOptions |
||
266 | */ |
||
267 | public function setOptions($options) |
||
272 | |||
273 | /** |
||
274 | * Change one option value specified by the user for this request. |
||
275 | * |
||
276 | * @param string $key |
||
277 | * @param mixed $value |
||
278 | * @return FormatterOptions |
||
279 | */ |
||
280 | public function setOption($key, $value) |
||
285 | |||
286 | /** |
||
287 | * Return a reference to the user-specified options for this request. |
||
288 | * |
||
289 | * @return array |
||
290 | */ |
||
291 | public function getOptions() |
||
295 | |||
296 | /** |
||
297 | * Provide a Symfony Console InputInterface containing the user-specified |
||
298 | * options for this request. |
||
299 | * |
||
300 | * @param InputInterface $input |
||
301 | * @return type |
||
302 | */ |
||
303 | public function setInput(InputInterface $input) |
||
307 | |||
308 | /** |
||
309 | * Return all of the options from the provided $defaults array that |
||
310 | * exist in our InputInterface object. |
||
311 | * |
||
312 | * @param array $defaults |
||
313 | * @return array |
||
314 | */ |
||
315 | public function getInputOptions($defaults) |
||
331 | } |
||
332 |