comparison vendor/symfony/console/Output/StreamOutput.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
18 /** 18 /**
19 * StreamOutput writes the output to a given stream. 19 * StreamOutput writes the output to a given stream.
20 * 20 *
21 * Usage: 21 * Usage:
22 * 22 *
23 * $output = new StreamOutput(fopen('php://stdout', 'w')); 23 * $output = new StreamOutput(fopen('php://stdout', 'w'));
24 * 24 *
25 * As `StreamOutput` can use any stream, you can also use a file: 25 * As `StreamOutput` can use any stream, you can also use a file:
26 * 26 *
27 * $output = new StreamOutput(fopen('/path/to/output.log', 'a', false)); 27 * $output = new StreamOutput(fopen('/path/to/output.log', 'a', false));
28 * 28 *
29 * @author Fabien Potencier <fabien@symfony.com> 29 * @author Fabien Potencier <fabien@symfony.com>
30 */ 30 */
31 class StreamOutput extends Output 31 class StreamOutput extends Output
32 { 32 {
40 * 40 *
41 * @throws InvalidArgumentException When first argument is not a real stream 41 * @throws InvalidArgumentException When first argument is not a real stream
42 */ 42 */
43 public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null) 43 public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
44 { 44 {
45 if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) { 45 if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) {
46 throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); 46 throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
47 } 47 }
48 48
49 $this->stream = $stream; 49 $this->stream = $stream;
50 50
68 /** 68 /**
69 * {@inheritdoc} 69 * {@inheritdoc}
70 */ 70 */
71 protected function doWrite($message, $newline) 71 protected function doWrite($message, $newline)
72 { 72 {
73 if (false === @fwrite($this->stream, $message) || ($newline && (false === @fwrite($this->stream, PHP_EOL)))) { 73 if ($newline) {
74 $message .= PHP_EOL;
75 }
76
77 if (false === @fwrite($this->stream, $message)) {
74 // should never happen 78 // should never happen
75 throw new RuntimeException('Unable to write output.'); 79 throw new RuntimeException('Unable to write output.');
76 } 80 }
77 81
78 fflush($this->stream); 82 fflush($this->stream);
91 * 95 *
92 * @return bool true if the stream supports colorization, false otherwise 96 * @return bool true if the stream supports colorization, false otherwise
93 */ 97 */
94 protected function hasColorSupport() 98 protected function hasColorSupport()
95 { 99 {
96 if (DIRECTORY_SEPARATOR === '\\') { 100 if ('Hyper' === getenv('TERM_PROGRAM')) {
97 return (function_exists('sapi_windows_vt100_support') 101 return true;
102 }
103
104 if (\DIRECTORY_SEPARATOR === '\\') {
105 return (\function_exists('sapi_windows_vt100_support')
98 && @sapi_windows_vt100_support($this->stream)) 106 && @sapi_windows_vt100_support($this->stream))
99 || false !== getenv('ANSICON') 107 || false !== getenv('ANSICON')
100 || 'ON' === getenv('ConEmuANSI') 108 || 'ON' === getenv('ConEmuANSI')
101 || 'xterm' === getenv('TERM'); 109 || 'xterm' === getenv('TERM');
102 } 110 }
103 111
104 if (function_exists('stream_isatty')) { 112 if (\function_exists('stream_isatty')) {
105 return @stream_isatty($this->stream); 113 return @stream_isatty($this->stream);
106 } 114 }
107 115
108 if (function_exists('posix_isatty')) { 116 if (\function_exists('posix_isatty')) {
109 return @posix_isatty($this->stream); 117 return @posix_isatty($this->stream);
110 } 118 }
111 119
112 $stat = @fstat($this->stream); 120 $stat = @fstat($this->stream);
113 // Check if formatted mode is S_IFCHR 121 // Check if formatted mode is S_IFCHR