Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/console/Output/Output.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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\Formatter\OutputFormatterInterface; | |
15 use Symfony\Component\Console\Formatter\OutputFormatter; | |
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 <fabien@symfony.com> | |
29 */ | |
30 abstract class Output implements OutputInterface | |
31 { | |
32 private $verbosity; | |
33 private $formatter; | |
34 | |
35 /** | |
36 * Constructor. | |
37 * | |
38 * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) | |
39 * @param bool $decorated Whether to decorate messages | |
40 * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) | |
41 */ | |
42 public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null) | |
43 { | |
44 $this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity; | |
45 $this->formatter = $formatter ?: new OutputFormatter(); | |
46 $this->formatter->setDecorated($decorated); | |
47 } | |
48 | |
49 /** | |
50 * {@inheritdoc} | |
51 */ | |
52 public function setFormatter(OutputFormatterInterface $formatter) | |
53 { | |
54 $this->formatter = $formatter; | |
55 } | |
56 | |
57 /** | |
58 * {@inheritdoc} | |
59 */ | |
60 public function getFormatter() | |
61 { | |
62 return $this->formatter; | |
63 } | |
64 | |
65 /** | |
66 * {@inheritdoc} | |
67 */ | |
68 public function setDecorated($decorated) | |
69 { | |
70 $this->formatter->setDecorated($decorated); | |
71 } | |
72 | |
73 /** | |
74 * {@inheritdoc} | |
75 */ | |
76 public function isDecorated() | |
77 { | |
78 return $this->formatter->isDecorated(); | |
79 } | |
80 | |
81 /** | |
82 * {@inheritdoc} | |
83 */ | |
84 public function setVerbosity($level) | |
85 { | |
86 $this->verbosity = (int) $level; | |
87 } | |
88 | |
89 /** | |
90 * {@inheritdoc} | |
91 */ | |
92 public function getVerbosity() | |
93 { | |
94 return $this->verbosity; | |
95 } | |
96 | |
97 /** | |
98 * {@inheritdoc} | |
99 */ | |
100 public function isQuiet() | |
101 { | |
102 return self::VERBOSITY_QUIET === $this->verbosity; | |
103 } | |
104 | |
105 /** | |
106 * {@inheritdoc} | |
107 */ | |
108 public function isVerbose() | |
109 { | |
110 return self::VERBOSITY_VERBOSE <= $this->verbosity; | |
111 } | |
112 | |
113 /** | |
114 * {@inheritdoc} | |
115 */ | |
116 public function isVeryVerbose() | |
117 { | |
118 return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity; | |
119 } | |
120 | |
121 /** | |
122 * {@inheritdoc} | |
123 */ | |
124 public function isDebug() | |
125 { | |
126 return self::VERBOSITY_DEBUG <= $this->verbosity; | |
127 } | |
128 | |
129 /** | |
130 * {@inheritdoc} | |
131 */ | |
132 public function writeln($messages, $options = self::OUTPUT_NORMAL) | |
133 { | |
134 $this->write($messages, true, $options); | |
135 } | |
136 | |
137 /** | |
138 * {@inheritdoc} | |
139 */ | |
140 public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL) | |
141 { | |
142 $messages = (array) $messages; | |
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 * @param string $message A message to write to the output | |
174 * @param bool $newline Whether to add a newline or not | |
175 */ | |
176 abstract protected function doWrite($message, $newline); | |
177 } |