Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / output-formatters / src / Formatters / TsvFormatter.php
1 <?php
2 namespace Consolidation\OutputFormatters\Formatters;
3
4 use Consolidation\OutputFormatters\Validate\ValidDataTypesInterface;
5 use Consolidation\OutputFormatters\Options\FormatterOptions;
6 use Consolidation\OutputFormatters\Transformations\TableTransformation;
7 use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
8 use Symfony\Component\Console\Output\OutputInterface;
9
10 /**
11  * Tab-separated value formatters
12  *
13  * Display the provided structured data in a tab-separated list.  Output
14  * escaping is much lighter, since there is no allowance for altering
15  * the delimiter.
16  */
17 class TsvFormatter extends CsvFormatter
18 {
19     protected function getDefaultFormatterOptions()
20     {
21         return [
22             FormatterOptions::INCLUDE_FIELD_LABELS => false,
23         ];
24     }
25
26     protected function writeOneLine(OutputInterface $output, $data, $options)
27     {
28         $output->writeln($this->tsvEscape($data));
29     }
30
31     protected function tsvEscape($data)
32     {
33         return implode("\t", array_map(
34             function ($item) {
35                 return str_replace(["\t", "\n"], ['\t', '\n'], $item);
36             },
37             $data
38         ));
39     }
40 }