9ca1e38602eddf85a5c4282ad6c227979d747b79
[yaffs-website] / vendor / consolidation / output-formatters / src / StructuredData / RowsOfFields.php
1 <?php
2 namespace Consolidation\OutputFormatters\StructuredData;
3
4 use Consolidation\OutputFormatters\Options\FormatterOptions;
5
6 /**
7  * Holds an array where each element of the array is one row,
8  * and each row contains an associative array where the keys
9  * are the field names, and the values are the field data.
10  *
11  * It is presumed that every row contains the same keys.
12  */
13 class RowsOfFields extends AbstractStructuredList implements ConversionInterface
14 {
15     /**
16      * @inheritdoc
17      */
18     public function convert(FormatterOptions $options)
19     {
20         $defaults = $this->defaultOptions();
21         $fields = $this->getFields($options, $defaults);
22         if (FieldProcessor::hasUnstructuredFieldAccess($fields)) {
23             return new UnstructuredListData($this->getArrayCopy());
24         }
25         return $this;
26     }
27
28     /**
29      * Restructure this data for output by converting it into a table
30      * transformation object.
31      *
32      * @param FormatterOptions $options Options that affect output formatting.
33      * @return Consolidation\OutputFormatters\Transformations\TableTransformation
34      */
35     public function restructure(FormatterOptions $options)
36     {
37         $data = $this->getArrayCopy();
38         return $this->createTableTransformation($data, $options);
39     }
40
41     public function getListData(FormatterOptions $options)
42     {
43         return array_keys($this->getArrayCopy());
44     }
45
46     protected function defaultOptions()
47     {
48         return [
49             FormatterOptions::LIST_ORIENTATION => false,
50         ] + parent::defaultOptions();
51     }
52 }