1 | <?php |
||
11 | class FormatterManager |
||
12 | { |
||
13 | protected $formatters = []; |
||
14 | |||
15 | 24 | public function __construct() |
|
32 | |||
33 | /** |
||
34 | * Format and write output |
||
35 | * |
||
36 | * @param OutputInterface $output Output stream to write to |
||
37 | * @param string $format Data format to output in |
||
38 | * @param mixed $structuredOutput Data to output |
||
39 | * @param array $configurationData Configuration information for formatter |
||
40 | * @param array $options User options |
||
41 | */ |
||
42 | 24 | public function write(OutputInterface $output, $format, $structuredOutput, $configurationData = [], $options = []) |
|
48 | |||
49 | 24 | protected function validateAndRestructure(FormatterInterface $formatter, $structuredOutput, $configurationData, $options) |
|
66 | |||
67 | /** |
||
68 | * Fetch the requested formatter. |
||
69 | * |
||
70 | * @param string $format Identifier for requested formatter |
||
71 | * @param array $configurationData Configuration data for formatter |
||
72 | * @return FormatterInterface |
||
73 | */ |
||
74 | 24 | public function getFormatter($format, $configurationData = []) |
|
86 | |||
87 | 24 | public function hasFormatter($format) |
|
91 | |||
92 | /** |
||
93 | * Determine if the provided data is compatible with the formatter being used. |
||
94 | * |
||
95 | * @param FormatterInterface $formatter Formatter being used |
||
96 | * @param mixed $structuredOutput Data to validate |
||
97 | * @return mixed |
||
98 | */ |
||
99 | 24 | public function validateData(FormatterInterface $formatter, $structuredOutput) |
|
115 | |||
116 | /** |
||
117 | * Restructure the data as necessary (e.g. to select or reorder fields). |
||
118 | * |
||
119 | * @param mixed $structuredOutput |
||
120 | * @param array $configurationData |
||
121 | * @param array $options |
||
122 | * @return mixed |
||
123 | */ |
||
124 | 24 | public function restructureData($structuredOutput, $configurationData, $options) |
|
131 | |||
132 | /** |
||
133 | * Allow the formatter access to the raw structured data prior |
||
134 | * to restructuring. For example, the 'list' formatter may wish |
||
135 | * to display the row keys when provided table output. If this |
||
136 | * function returns a result that does not evaluate to 'false', |
||
137 | * then that result will be used as-is, and restructuring and |
||
138 | * validation will not occur. |
||
139 | * |
||
140 | * @param mixed $structuredOutput |
||
141 | * @param array $configurationData |
||
142 | * @param array $options |
||
143 | * @return mixed |
||
144 | */ |
||
145 | 24 | public function overrideRestructure(FormatterInterface $formatter, $structuredOutput, $configurationData, $options) |
|
151 | } |
||
152 |