2 namespace Consolidation\OutputFormatters\StructuredData;
4 use Consolidation\OutputFormatters\Options\FormatterOptions;
5 use Consolidation\OutputFormatters\StructuredData\ListDataInterface;
6 use Consolidation\OutputFormatters\Transformations\PropertyParser;
7 use Consolidation\OutputFormatters\Transformations\ReorderFields;
8 use Consolidation\OutputFormatters\Transformations\TableTransformation;
9 use Consolidation\OutputFormatters\Transformations\PropertyListTableTransformation;
12 * Holds an array where each element of the array is one
13 * key : value pair. The keys must be unique, as is typically
14 * the case for associative arrays.
16 class PropertyList extends AbstractStructuredList
19 * Restructure this data for output by converting it into a table
20 * transformation object.
22 * @param FormatterOptions $options Options that affect output formatting.
23 * @return Consolidation\OutputFormatters\Transformations\TableTransformation
25 public function restructure(FormatterOptions $options)
27 $data = [$this->getArrayCopy()];
28 $options->setConfigurationDefault('list-orientation', true);
29 $tableTransformer = $this->createTableTransformation($data, $options);
30 return $tableTransformer;
33 public function getListData(FormatterOptions $options)
35 $data = $this->getArrayCopy();
37 $defaults = $this->defaultOptions();
38 $fieldLabels = $this->getReorderedFieldLabels([$data], $options, $defaults);
41 foreach ($fieldLabels as $id => $label) {
42 $result[$id] = $data[$id];
47 protected function defaultOptions()
50 FormatterOptions::LIST_ORIENTATION => true,
51 ] + parent::defaultOptions();
54 protected function instantiateTableTransformation($data, $fieldLabels, $rowLabels)
56 return new PropertyListTableTransformation($data, $fieldLabels, $rowLabels);