123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace Symfony\Component\Console\Output;
- use Symfony\Component\Console\Formatter\OutputFormatterInterface;
- class StreamOutput extends Output
- {
- private $stream;
-
- public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
- {
- if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
- throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
- }
- $this->stream = $stream;
- if (null === $decorated) {
- $decorated = $this->hasColorSupport();
- }
- parent::__construct($verbosity, $decorated, $formatter);
- }
-
- public function getStream()
- {
- return $this->stream;
- }
-
- protected function doWrite($message, $newline)
- {
- if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) {
-
-
- throw new \RuntimeException('Unable to write output.');
-
- }
- fflush($this->stream);
- }
-
- protected function hasColorSupport()
- {
-
- if (DIRECTORY_SEPARATOR == '\\') {
- return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
- }
- return function_exists('posix_isatty') && @posix_isatty($this->stream);
-
- }
- }
|