[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <[email protected]> 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 * ConsoleOutput is the default class for all CLI output. It uses STDOUT and STDERR. 18 * 19 * This class is a convenient wrapper around `StreamOutput` for both STDOUT and STDERR. 20 * 21 * $output = new ConsoleOutput(); 22 * 23 * This is equivalent to: 24 * 25 * $output = new StreamOutput(fopen('php://stdout', 'w')); 26 * $stdErr = new StreamOutput(fopen('php://stderr', 'w')); 27 * 28 * @author Fabien Potencier <[email protected]> 29 */ 30 class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface 31 { 32 private $stderr; 33 private $consoleSectionOutputs = []; 34 35 /** 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 public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) 41 { 42 parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter); 43 44 if (null === $formatter) { 45 // for BC reasons, stdErr has it own Formatter only when user don't inject a specific formatter. 46 $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated); 47 48 return; 49 } 50 51 $actualDecorated = $this->isDecorated(); 52 $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter()); 53 54 if (null === $decorated) { 55 $this->setDecorated($actualDecorated && $this->stderr->isDecorated()); 56 } 57 } 58 59 /** 60 * Creates a new output section. 61 */ 62 public function section(): ConsoleSectionOutput 63 { 64 return new ConsoleSectionOutput($this->getStream(), $this->consoleSectionOutputs, $this->getVerbosity(), $this->isDecorated(), $this->getFormatter()); 65 } 66 67 /** 68 * {@inheritdoc} 69 */ 70 public function setDecorated(bool $decorated) 71 { 72 parent::setDecorated($decorated); 73 $this->stderr->setDecorated($decorated); 74 } 75 76 /** 77 * {@inheritdoc} 78 */ 79 public function setFormatter(OutputFormatterInterface $formatter) 80 { 81 parent::setFormatter($formatter); 82 $this->stderr->setFormatter($formatter); 83 } 84 85 /** 86 * {@inheritdoc} 87 */ 88 public function setVerbosity(int $level) 89 { 90 parent::setVerbosity($level); 91 $this->stderr->setVerbosity($level); 92 } 93 94 /** 95 * {@inheritdoc} 96 */ 97 public function getErrorOutput() 98 { 99 return $this->stderr; 100 } 101 102 /** 103 * {@inheritdoc} 104 */ 105 public function setErrorOutput(OutputInterface $error) 106 { 107 $this->stderr = $error; 108 } 109 110 /** 111 * Returns true if current environment supports writing console output to 112 * STDOUT. 113 * 114 * @return bool 115 */ 116 protected function hasStdoutSupport() 117 { 118 return false === $this->isRunningOS400(); 119 } 120 121 /** 122 * Returns true if current environment supports writing console output to 123 * STDERR. 124 * 125 * @return bool 126 */ 127 protected function hasStderrSupport() 128 { 129 return false === $this->isRunningOS400(); 130 } 131 132 /** 133 * Checks if current executing environment is IBM iSeries (OS400), which 134 * doesn't properly convert character-encodings between ASCII to EBCDIC. 135 */ 136 private function isRunningOS400(): bool 137 { 138 $checks = [ 139 \function_exists('php_uname') ? php_uname('s') : '', 140 getenv('OSTYPE'), 141 \PHP_OS, 142 ]; 143 144 return false !== stripos(implode(';', $checks), 'OS400'); 145 } 146 147 /** 148 * @return resource 149 */ 150 private function openOutputStream() 151 { 152 if (!$this->hasStdoutSupport()) { 153 return fopen('php://output', 'w'); 154 } 155 156 // Use STDOUT when possible to prevent from opening too many file descriptors 157 return \defined('STDOUT') ? \STDOUT : (@fopen('php://stdout', 'w') ?: fopen('php://output', 'w')); 158 } 159 160 /** 161 * @return resource 162 */ 163 private function openErrorStream() 164 { 165 if (!$this->hasStderrSupport()) { 166 return fopen('php://output', 'w'); 167 } 168 169 // Use STDERR when possible to prevent from opening too many file descriptors 170 return \defined('STDERR') ? \STDERR : (@fopen('php://stderr', 'w') ?: fopen('php://output', 'w')); 171 } 172 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |