[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/console/Symfony/Component/Console/Output/ -> StreamOutput.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\Console\Output;
  13  
  14  use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  15  
  16  /**
  17   * StreamOutput writes the output to a given stream.
  18   *
  19   * Usage:
  20   *
  21   * $output = new StreamOutput(fopen('php://stdout', 'w'));
  22   *
  23   * As `StreamOutput` can use any stream, you can also use a file:
  24   *
  25   * $output = new StreamOutput(fopen('/path/to/output.log', 'a', false));
  26   *
  27   * @author Fabien Potencier <fabien@symfony.com>
  28   */
  29  class StreamOutput extends Output
  30  {
  31      private $stream;
  32  
  33      /**
  34       * Constructor.
  35       *
  36       * @param resource                      $stream    A stream resource
  37       * @param int                           $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
  38       * @param bool|null                     $decorated Whether to decorate messages (null for auto-guessing)
  39       * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
  40       *
  41       * @throws \InvalidArgumentException When first argument is not a real stream
  42       */
  43      public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
  44      {
  45          if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
  46              throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
  47          }
  48  
  49          $this->stream = $stream;
  50  
  51          if (null === $decorated) {
  52              $decorated = $this->hasColorSupport();
  53          }
  54  
  55          parent::__construct($verbosity, $decorated, $formatter);
  56      }
  57  
  58      /**
  59       * Gets the stream attached to this StreamOutput instance.
  60       *
  61       * @return resource A stream resource
  62       */
  63      public function getStream()
  64      {
  65          return $this->stream;
  66      }
  67  
  68      /**
  69       * {@inheritdoc}
  70       */
  71      protected function doWrite($message, $newline)
  72      {
  73          if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) {
  74              // @codeCoverageIgnoreStart
  75              // should never happen
  76              throw new \RuntimeException('Unable to write output.');
  77              // @codeCoverageIgnoreEnd
  78          }
  79  
  80          fflush($this->stream);
  81      }
  82  
  83      /**
  84       * Returns true if the stream supports colorization.
  85       *
  86       * Colorization is disabled if not supported by the stream:
  87       *
  88       *  -  Windows before 10.0.10586 without Ansicon, ConEmu or Mintty
  89       *  -  non tty consoles
  90       *
  91       * @return bool true if the stream supports colorization, false otherwise
  92       */
  93      protected function hasColorSupport()
  94      {
  95          // @codeCoverageIgnoreStart
  96          if (DIRECTORY_SEPARATOR === '\\') {
  97              return
  98                  0 >= version_compare('10.0.10586', PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD)
  99                  || false !== getenv('ANSICON')
 100                  || 'ON' === getenv('ConEmuANSI')
 101                  || 'xterm' === getenv('TERM');
 102          }
 103  
 104          return function_exists('posix_isatty') && @posix_isatty($this->stream);
 105          // @codeCoverageIgnoreEnd
 106      }
 107  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1