PluginProbe
Depicter — Popup & Slider Builder / 1.2.0
Depicter — Popup & Slider Builder v1.2.0
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / Output / StreamOutput.php

StreamOutput.php in Depicter — Popup & Slider Builder 1.2.0, at vendor/symfony/console/Output/StreamOutput.php

116 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Exception\InvalidArgumentException;
15 use Symfony\Component\Console\Formatter\OutputFormatterInterface;
16
17 /**
18 * StreamOutput writes the output to a given stream.
19 *
20 * Usage:
21 *
22 * $output = new StreamOutput(fopen('php://stdout', 'w'));
23 *
24 * As `StreamOutput` can use any stream, you can also use a file:
25 *
26 * $output = new StreamOutput(fopen('/path/to/output.log', 'a', false));
27 *
28 * @author Fabien Potencier <fabien@symfony.com>
29 */
30 class StreamOutput extends Output
31 {
32 private $stream;
33
34 /**
35 * @param resource $stream A stream resource
36 * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
37 * @param bool|null $decorated Whether to decorate messages (null for auto-guessing)
38 * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
39 *
40 * @throws InvalidArgumentException When first argument is not a real stream
41 */
42 public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null)
43 {
44 if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) {
45 throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
46 }
47
48 $this->stream = $stream;
49
50 if (null === $decorated) {
51 $decorated = $this->hasColorSupport();
52 }
53
54 parent::__construct($verbosity, $decorated, $formatter);
55 }
56
57 /**
58 * Gets the stream attached to this StreamOutput instance.
59 *
60 * @return resource A stream resource
61 */
62 public function getStream()
63 {
64 return $this->stream;
65 }
66
67 /**
68 * {@inheritdoc}
69 */
70 protected function doWrite(string $message, bool $newline)
71 {
72 if ($newline) {
73 $message .= \PHP_EOL;
74 }
75
76 @fwrite($this->stream, $message);
77
78 fflush($this->stream);
79 }
80
81 /**
82 * Returns true if the stream supports colorization.
83 *
84 * Colorization is disabled if not supported by the stream:
85 *
86 * This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo
87 * terminals via named pipes, so we can only check the environment.
88 *
89 * Reference: Composer\XdebugHandler\Process::supportsColor
90 * https://github.com/composer/xdebug-handler
91 *
92 * @return bool true if the stream supports colorization, false otherwise
93 */
94 protected function hasColorSupport()
95 {
96 // Follow https://no-color.org/
97 if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) {
98 return false;
99 }
100
101 if ('Hyper' === getenv('TERM_PROGRAM')) {
102 return true;
103 }
104
105 if (\DIRECTORY_SEPARATOR === '\\') {
106 return (\function_exists('sapi_windows_vt100_support')
107 && @sapi_windows_vt100_support($this->stream))
108 || false !== getenv('ANSICON')
109 || 'ON' === getenv('ConEmuANSI')
110 || 'xterm' === getenv('TERM');
111 }
112
113 return stream_isatty($this->stream);
114 }
115 }
116