Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MultipleStreamOutput.php
Go to the documentation of this file.
1 <?php
7 
8 use Symfony\Component\Console\Formatter\OutputFormatterInterface;
9 use Symfony\Component\Console\Output\Output;
10 
14 class MultipleStreamOutput extends Output
15 {
19  private $streams;
20 
29  public function __construct(
30  array $streams,
31  $verbosity = self::VERBOSITY_NORMAL,
32  $decorated = false,
33  OutputFormatterInterface $formatter = null
34  ) {
35  foreach ($streams as $stream) {
36  if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
37  throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
38  }
39  }
40  $this->streams = $streams;
41  parent::__construct($verbosity, $decorated, $formatter);
42  }
43 
47  protected function doWrite($message, $newline)
48  {
49  foreach ($this->streams as $stream) {
50  if (false === @fwrite($stream, $message . ($newline ? PHP_EOL : ''))) {
51  // should never happen
52  throw new \RuntimeException('Unable to write output.');
53  }
54 
55  fflush($stream);
56  }
57  }
58 }
__construct(array $streams, $verbosity=self::VERBOSITY_NORMAL, $decorated=false, OutputFormatterInterface $formatter=null)
$message