Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 181 lines (163 sloc) 4.849 kb
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
1 <?php
2
3 /*
4a83d99 @blue-eyes normalized license messages in PHP files
blue-eyes authored
4 * This file is part of the Symfony package.
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
5 *
b933805 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
6 * (c) Fabien Potencier <fabien@symfony.com>
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
7 *
4a83d99 @blue-eyes normalized license messages in PHP files
blue-eyes authored
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
10 */
11
4a83d99 @blue-eyes normalized license messages in PHP files
blue-eyes authored
12 namespace Symfony\Component\Console\Output;
13
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
14 use Symfony\Component\Console\Formatter\OutputFormatterInterface;
15 use Symfony\Component\Console\Formatter\OutputFormatter;
16
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
17 /**
18 * Base class for output classes.
19 *
dedc821 @javiereguiluz [Console][Output] Fixed some minor typos and grammatical errors
javiereguiluz authored
20 * There are three levels of verbosity:
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
21 *
22 * * normal: no option passed (normal output - information)
23 * * verbose: -v (more output - debug)
24 * * quiet: -q (no output)
25 *
b933805 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
26 * @author Fabien Potencier <fabien@symfony.com>
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
27 *
28 * @api
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
29 */
30 abstract class Output implements OutputInterface
31 {
dc6d7a7 @everzet [Console] privatized protected variables, cuz they now have getters/sett...
everzet authored
32 private $verbosity;
33 private $formatter;
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
34
35 /**
36 * Constructor.
37 *
4ec78d1 @pborreli [Phpdoc] Cleaning/fixing
pborreli authored
38 * @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL, self::VERBOSITY_VERBOSE)
39 * @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
40 * @param OutputFormatterInterface $formatter Output formatter instance
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
41 *
42 * @api
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
43 */
4e668e9 @everzet [Console] moved whole constructor definitions in one line
everzet authored
44 public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
45 {
46 $this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
f48469a @Tobion replaced command names with supported placeholders in help texts
Tobion authored
47 $this->formatter = null === $formatter ? new OutputFormatter() : $formatter;
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
48 $this->formatter->setDecorated((Boolean) $decorated);
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
49 }
50
51 /**
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
52 * Sets output formatter.
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
53 *
4ec78d1 @pborreli [Phpdoc] Cleaning/fixing
pborreli authored
54 * @param OutputFormatterInterface $formatter
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
55 *
56 * @api
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
57 */
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
58 public function setFormatter(OutputFormatterInterface $formatter)
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
59 {
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
60 $this->formatter = $formatter;
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
61 }
62
63 /**
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
64 * Returns current output formatter instance.
c6f6536 @everzet we need ability to get style parameters same way we set them with setSty...
everzet authored
65 *
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
66 * @return OutputFormatterInterface
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
67 *
68 * @api
c6f6536 @everzet we need ability to get style parameters same way we set them with setSty...
everzet authored
69 */
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
70 public function getFormatter()
c6f6536 @everzet we need ability to get style parameters same way we set them with setSty...
everzet authored
71 {
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
72 return $this->formatter;
c6f6536 @everzet we need ability to get style parameters same way we set them with setSty...
everzet authored
73 }
74
75 /**
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
76 * Sets the decorated flag.
77 *
dedc821 @javiereguiluz [Console][Output] Fixed some minor typos and grammatical errors
javiereguiluz authored
78 * @param Boolean $decorated Whether to decorate the messages or not
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
79 *
80 * @api
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
81 */
82 public function setDecorated($decorated)
83 {
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
84 $this->formatter->setDecorated((Boolean) $decorated);
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
85 }
86
87 /**
88 * Gets the decorated flag.
89 *
90 * @return Boolean true if the output will decorate messages, false otherwise
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
91 *
92 * @api
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
93 */
94 public function isDecorated()
95 {
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
96 return $this->formatter->isDecorated();
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
97 }
98
99 /**
100 * Sets the verbosity of the output.
101 *
102 * @param integer $level The level of verbosity
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
103 *
104 * @api
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
105 */
106 public function setVerbosity($level)
107 {
108 $this->verbosity = (int) $level;
109 }
110
111 /**
112 * Gets the current verbosity of the output.
113 *
114 * @return integer The current level of verbosity
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
115 *
116 * @api
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
117 */
118 public function getVerbosity()
119 {
120 return $this->verbosity;
121 }
122
123 /**
124 * Writes a message to the output and adds a newline at the end.
125 *
126 * @param string|array $messages The message as an array of lines of a single string
127 * @param integer $type The type of output
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
128 *
129 * @api
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
130 */
131 public function writeln($messages, $type = 0)
132 {
133 $this->write($messages, true, $type);
134 }
135
136 /**
137 * Writes a message to the output.
138 *
139 * @param string|array $messages The message as an array of lines of a single string
140 * @param Boolean $newline Whether to add a newline or not
141 * @param integer $type The type of output
142 *
143 * @throws \InvalidArgumentException When unknown output type is given
00b2567 @fabpot [Console] tagged the guaranteed BC API
fabpot authored
144 *
145 * @api
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
146 */
147 public function write($messages, $newline = false, $type = 0)
148 {
149 if (self::VERBOSITY_QUIET === $this->verbosity) {
150 return;
151 }
152
27547b7 @vicb Make casting scalar to array consistent
vicb authored
153 $messages = (array) $messages;
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
154
155 foreach ($messages as $message) {
156 switch ($type) {
4412424 @fabpot [Console] moved Output constants to OutputInterface
fabpot authored
157 case OutputInterface::OUTPUT_NORMAL:
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
158 $message = $this->formatter->format($message);
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
159 break;
4412424 @fabpot [Console] moved Output constants to OutputInterface
fabpot authored
160 case OutputInterface::OUTPUT_RAW:
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
161 break;
4412424 @fabpot [Console] moved Output constants to OutputInterface
fabpot authored
162 case OutputInterface::OUTPUT_PLAIN:
aedbe56 @everzet [Console] updated console output to support new output formatter and sty...
everzet authored
163 $message = strip_tags($this->formatter->format($message));
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
164 break;
165 default:
166 throw new \InvalidArgumentException(sprintf('Unknown output type given (%s)', $type));
167 }
168
169 $this->doWrite($message, $newline);
170 }
171 }
172
173 /**
174 * Writes a message to the output.
175 *
176 * @param string $message A message to write to the output
177 * @param Boolean $newline Whether to add a newline or not
178 */
afc5ecf @kriswallsmith [Console] reduced visibility to protected
kriswallsmith authored
179 abstract protected function doWrite($message, $newline);
68c191c @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
180 }
Something went wrong with that request. Please try again.