validDataTypes() ); } return $structuredData; } /** * @inheritdoc */ public function write(OutputInterface $output, $tableTransformer, FormatterOptions $options) { $headers = []; $defaults = [ FormatterOptions::TABLE_STYLE => 'consolidation', FormatterOptions::INCLUDE_FIELD_LABELS => true, ]; $table = new Table($output); static::addCustomTableStyles($table); $table->setStyle($options->get(FormatterOptions::TABLE_STYLE, $defaults)); $isList = $tableTransformer->isList(); $includeHeaders = $options->get(FormatterOptions::INCLUDE_FIELD_LABELS, $defaults); $listDelimiter = $options->get(FormatterOptions::LIST_DELIMITER, $defaults); $headers = $tableTransformer->getHeaders(); $data = $tableTransformer->getTableData($includeHeaders && $isList); if ($listDelimiter) { if (!empty($headers)) { array_splice($headers, 1, 0, ':'); } $data = array_map(function ($item) { array_splice($item, 1, 0, ':'); return $item; }, $data); } if ($includeHeaders && !$isList) { $table->setHeaders($headers); } // todo: $output->getFormatter(); $data = $this->wrap($headers, $data, $table->getStyle(), $options); $table->setRows($data); $table->render(); } /** * Wrap the table data * @param array $data * @param TableStyle $tableStyle * @param FormatterOptions $options * @return array */ protected function wrap($headers, $data, TableStyle $tableStyle, FormatterOptions $options) { $wrapper = new WordWrapper($options->get(FormatterOptions::TERMINAL_WIDTH)); $wrapper->setPaddingFromStyle($tableStyle); if (!empty($headers)) { $headerLengths = array_map(function ($item) { return strlen($item); }, $headers); $wrapper->setMinimumWidths($headerLengths); } return $wrapper->wrap($data); } /** * Add our custom table style(s) to the table. */ protected static function addCustomTableStyles($table) { // The 'consolidation' style is the same as the 'symfony-style-guide' // style, except it maintains the colored headers used in 'default'. $consolidationStyle = new TableStyle(); $consolidationStyle ->setHorizontalBorderChar('-') ->setVerticalBorderChar(' ') ->setCrossingChar(' ') ; $table->setStyleDefinition('consolidation', $consolidationStyle); } }