[ 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\OutputFormatter; 15 use Symfony\Component\Console\Formatter\OutputFormatterInterface; 16 17 /** 18 * Base class for output classes. 19 * 20 * There are five levels of verbosity: 21 * 22 * * normal: no option passed (normal output) 23 * * verbose: -v (more output) 24 * * very verbose: -vv (highly extended output) 25 * * debug: -vvv (all debug output) 26 * * quiet: -q (no output) 27 * 28 * @author Fabien Potencier <[email protected]> 29 */ 30 abstract class Output implements OutputInterface 31 { 32 private $verbosity; 33 private $formatter; 34 35 /** 36 * @param int|null $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) 37 * @param bool $decorated Whether to decorate messages 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 = false, OutputFormatterInterface $formatter = null) 41 { 42 $this->verbosity = $verbosity ?? self::VERBOSITY_NORMAL; 43 $this->formatter = $formatter ?? new OutputFormatter(); 44 $this->formatter->setDecorated($decorated); 45 } 46 47 /** 48 * {@inheritdoc} 49 */ 50 public function setFormatter(OutputFormatterInterface $formatter) 51 { 52 $this->formatter = $formatter; 53 } 54 55 /** 56 * {@inheritdoc} 57 */ 58 public function getFormatter() 59 { 60 return $this->formatter; 61 } 62 63 /** 64 * {@inheritdoc} 65 */ 66 public function setDecorated(bool $decorated) 67 { 68 $this->formatter->setDecorated($decorated); 69 } 70 71 /** 72 * {@inheritdoc} 73 */ 74 public function isDecorated() 75 { 76 return $this->formatter->isDecorated(); 77 } 78 79 /** 80 * {@inheritdoc} 81 */ 82 public function setVerbosity(int $level) 83 { 84 $this->verbosity = $level; 85 } 86 87 /** 88 * {@inheritdoc} 89 */ 90 public function getVerbosity() 91 { 92 return $this->verbosity; 93 } 94 95 /** 96 * {@inheritdoc} 97 */ 98 public function isQuiet() 99 { 100 return self::VERBOSITY_QUIET === $this->verbosity; 101 } 102 103 /** 104 * {@inheritdoc} 105 */ 106 public function isVerbose() 107 { 108 return self::VERBOSITY_VERBOSE <= $this->verbosity; 109 } 110 111 /** 112 * {@inheritdoc} 113 */ 114 public function isVeryVerbose() 115 { 116 return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity; 117 } 118 119 /** 120 * {@inheritdoc} 121 */ 122 public function isDebug() 123 { 124 return self::VERBOSITY_DEBUG <= $this->verbosity; 125 } 126 127 /** 128 * {@inheritdoc} 129 */ 130 public function writeln($messages, int $options = self::OUTPUT_NORMAL) 131 { 132 $this->write($messages, true, $options); 133 } 134 135 /** 136 * {@inheritdoc} 137 */ 138 public function write($messages, bool $newline = false, int $options = self::OUTPUT_NORMAL) 139 { 140 if (!is_iterable($messages)) { 141 $messages = [$messages]; 142 } 143 144 $types = self::OUTPUT_NORMAL | self::OUTPUT_RAW | self::OUTPUT_PLAIN; 145 $type = $types & $options ?: self::OUTPUT_NORMAL; 146 147 $verbosities = self::VERBOSITY_QUIET | self::VERBOSITY_NORMAL | self::VERBOSITY_VERBOSE | self::VERBOSITY_VERY_VERBOSE | self::VERBOSITY_DEBUG; 148 $verbosity = $verbosities & $options ?: self::VERBOSITY_NORMAL; 149 150 if ($verbosity > $this->getVerbosity()) { 151 return; 152 } 153 154 foreach ($messages as $message) { 155 switch ($type) { 156 case OutputInterface::OUTPUT_NORMAL: 157 $message = $this->formatter->format($message); 158 break; 159 case OutputInterface::OUTPUT_RAW: 160 break; 161 case OutputInterface::OUTPUT_PLAIN: 162 $message = strip_tags($this->formatter->format($message)); 163 break; 164 } 165 166 $this->doWrite($message ?? '', $newline); 167 } 168 } 169 170 /** 171 * Writes a message to the output. 172 */ 173 abstract protected function doWrite(string $message, bool $newline); 174 }
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 |