Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / consolidation / output-formatters / src / Formatters / VarDumpFormatter.php
1 <?php
2
3 namespace Consolidation\OutputFormatters\Formatters;
4
5 use Consolidation\OutputFormatters\Options\FormatterOptions;
6 use Symfony\Component\Console\Output\OutputInterface;
7 use Symfony\Component\Console\Output\StreamOutput;
8 use Symfony\Component\VarDumper\Cloner\VarCloner;
9 use Symfony\Component\VarDumper\Dumper\CliDumper;
10
11 /**
12  * Var_dump formatter
13  *
14  * Run provided data through Symfony VarDumper component.
15  */
16 class VarDumpFormatter implements FormatterInterface
17 {
18     /**
19      * @inheritdoc
20      */
21     public function write(OutputInterface $output, $data, FormatterOptions $options)
22     {
23         $dumper = new CliDumper();
24         $cloned_data = (new VarCloner())->cloneVar($data);
25
26         if ($output instanceof StreamOutput) {
27             // When stream output is used the dumper is smart enough to
28             // determine whether or not to apply colors to the dump.
29             // @see Symfony\Component\VarDumper\Dumper\CliDumper::supportsColors
30             $dumper->dump($cloned_data, $output->getStream());
31         } else {
32             // @todo Use dumper return value to get output once we stop support
33             // VarDumper v2.
34             $stream = fopen('php://memory', 'r+b');
35             $dumper->dump($cloned_data, $stream);
36             $output->writeln(stream_get_contents($stream, -1, 0));
37             fclose($stream);
38         }
39     }
40 }