TYPO3  7.6
Output.php
Go to the documentation of this file.
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 
16 
32 abstract class Output implements OutputInterface
33 {
34  private $verbosity;
35  private $formatter;
36 
46  public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null)
47  {
48  $this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
49  $this->formatter = $formatter ?: new OutputFormatter();
50  $this->formatter->setDecorated($decorated);
51  }
52 
57  {
58  $this->formatter = $formatter;
59  }
60 
64  public function getFormatter()
65  {
66  return $this->formatter;
67  }
68 
72  public function setDecorated($decorated)
73  {
74  $this->formatter->setDecorated($decorated);
75  }
76 
80  public function isDecorated()
81  {
82  return $this->formatter->isDecorated();
83  }
84 
88  public function setVerbosity($level)
89  {
90  $this->verbosity = (int) $level;
91  }
92 
96  public function getVerbosity()
97  {
98  return $this->verbosity;
99  }
100 
101  public function isQuiet()
102  {
103  return self::VERBOSITY_QUIET === $this->verbosity;
104  }
105 
106  public function isVerbose()
107  {
108  return self::VERBOSITY_VERBOSE <= $this->verbosity;
109  }
110 
111  public function isVeryVerbose()
112  {
113  return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity;
114  }
115 
116  public function isDebug()
117  {
118  return self::VERBOSITY_DEBUG <= $this->verbosity;
119  }
120 
124  public function writeln($messages, $type = self::OUTPUT_NORMAL)
125  {
126  $this->write($messages, true, $type);
127  }
128 
132  public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
133  {
134  if (self::VERBOSITY_QUIET === $this->verbosity) {
135  return;
136  }
137 
138  $messages = (array) $messages;
139 
140  foreach ($messages as $message) {
141  switch ($type) {
143  $message = $this->formatter->format($message);
144  break;
146  break;
148  $message = strip_tags($this->formatter->format($message));
149  break;
150  default:
151  throw new \InvalidArgumentException(sprintf('Unknown output type given (%s)', $type));
152  }
153 
154  $this->doWrite($message, $newline);
155  }
156  }
157 
164  abstract protected function doWrite($message, $newline);
165 }