X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fconsolidation%2Foutput-formatters%2Fsrc%2FStructuredData%2FAbstractStructuredList.php;fp=vendor%2Fconsolidation%2Foutput-formatters%2Fsrc%2FStructuredData%2FAbstractStructuredList.php;h=fb1bc5375ff23d035d2b85a9264278880294a204;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/consolidation/output-formatters/src/StructuredData/AbstractStructuredList.php b/vendor/consolidation/output-formatters/src/StructuredData/AbstractStructuredList.php new file mode 100644 index 000000000..fb1bc5375 --- /dev/null +++ b/vendor/consolidation/output-formatters/src/StructuredData/AbstractStructuredList.php @@ -0,0 +1,90 @@ +defaultOptions(); + $fieldLabels = $this->getReorderedFieldLabels($data, $options, $defaults); + + $tableTransformer = $this->instantiateTableTransformation($data, $fieldLabels, $options->get(FormatterOptions::ROW_LABELS, $defaults)); + if ($options->get(FormatterOptions::LIST_ORIENTATION, $defaults)) { + $tableTransformer->setLayout(TableTransformation::LIST_LAYOUT); + } + + return $tableTransformer; + } + + protected function instantiateTableTransformation($data, $fieldLabels, $rowLabels) + { + return new TableTransformation($data, $fieldLabels, $rowLabels); + } + + protected function getReorderedFieldLabels($data, $options, $defaults) + { + $reorderer = new ReorderFields(); + $fieldLabels = $reorderer->reorder( + $this->getFields($options, $defaults), + $options->get(FormatterOptions::FIELD_LABELS, $defaults), + $data + ); + return $fieldLabels; + } + + protected function getFields($options, $defaults) + { + $fieldShortcut = $options->get(FormatterOptions::FIELD); + if (!empty($fieldShortcut)) { + return [$fieldShortcut]; + } + $result = $options->get(FormatterOptions::FIELDS, $defaults); + if (!empty($result)) { + return $result; + } + return $options->get(FormatterOptions::DEFAULT_FIELDS, $defaults); + } + + /** + * A structured list may provide its own set of default options. These + * will be used in place of the command's default options (from the + * annotations) in instances where the user does not provide the options + * explicitly (on the commandline) or implicitly (via a configuration file). + * + * @return array + */ + protected function defaultOptions() + { + return [ + FormatterOptions::FIELDS => [], + FormatterOptions::FIELD_LABELS => [], + FormatterOptions::ROW_LABELS => [], + FormatterOptions::DEFAULT_FIELDS => [], + ]; + } +}