MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Output.php
Ir para a documentação deste ficheiro.
1
<?php
2
3
namespace
Symfony\Component\Console\Output
;
4
5
/*
6
* This file is part of the Symfony framework.
7
*
8
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
9
*
10
* This source file is subject to the MIT license that is bundled
11
* with this source code in the file LICENSE.
12
*/
13
25
abstract
class
Output
implements
OutputInterface
26
{
27
const
VERBOSITY_QUIET
= 0;
28
const
VERBOSITY_NORMAL
= 1;
29
const
VERBOSITY_VERBOSE
= 2;
30
31
const
OUTPUT_NORMAL
= 0;
32
const
OUTPUT_RAW
= 1;
33
const
OUTPUT_PLAIN
= 2;
34
35
protected
$verbosity
;
36
protected
$decorated
;
37
38
static
protected
$styles
= array(
39
'error'
=> array(
'bg'
=>
'red'
,
'fg'
=>
'white'
),
40
'info'
=> array(
'fg'
=>
'green'
),
41
'comment'
=> array(
'fg'
=>
'yellow'
),
42
'question'
=> array(
'bg'
=>
'cyan'
,
'fg'
=>
'black'
),
43
);
44
static
protected
$options
= array(
'bold'
=> 1,
'underscore'
=> 4,
'blink'
=> 5,
'reverse'
=> 7,
'conceal'
=> 8);
45
static
protected
$foreground
= array(
'black'
=> 30,
'red'
=> 31,
'green'
=> 32,
'yellow'
=> 33,
'blue'
=> 34,
'magenta'
=> 35,
'cyan'
=> 36,
'white'
=> 37);
46
static
protected
$background
= array(
'black'
=> 40,
'red'
=> 41,
'green'
=> 42,
'yellow'
=> 43,
'blue'
=> 44,
'magenta'
=> 45,
'cyan'
=> 46,
'white'
=> 47);
47
54
public
function
__construct
(
$verbosity
= self::VERBOSITY_NORMAL,
$decorated
=
null
)
55
{
56
$this->decorated = (Boolean)
$decorated
;
57
$this->verbosity =
null
===
$verbosity
?
self::VERBOSITY_NORMAL
:
$verbosity
;
58
}
59
66
static
public
function
setStyle
($name,
$options
= array())
67
{
68
static::$styles[strtolower($name)] =
$options
;
69
}
70
76
public
function
setDecorated
(
$decorated
)
77
{
78
$this->decorated = (Boolean)
$decorated
;
79
}
80
86
public
function
isDecorated
()
87
{
88
return
$this->decorated
;
89
}
90
96
public
function
setVerbosity
($level)
97
{
98
$this->verbosity = (int) $level;
99
}
100
106
public
function
getVerbosity
()
107
{
108
return
$this->verbosity
;
109
}
110
117
public
function
writeln
($messages, $type = 0)
118
{
119
$this->
write
($messages,
true
, $type);
120
}
121
131
public
function
write
($messages, $newline =
false
, $type = 0)
132
{
133
if
(self::VERBOSITY_QUIET === $this->verbosity) {
134
return
;
135
}
136
137
if
(!is_array($messages)) {
138
$messages = array($messages);
139
}
140
141
foreach
($messages as $message) {
142
switch
($type) {
143
case
Output::OUTPUT_NORMAL
:
144
$message = $this->
format
($message);
145
break
;
146
case
Output::OUTPUT_RAW
:
147
break
;
148
case
Output::OUTPUT_PLAIN
:
149
$message = strip_tags($this->
format
($message));
150
break
;
151
default
:
152
throw
new \InvalidArgumentException(sprintf(
'Unknown output type given (%s)'
, $type));
153
}
154
155
$this->
doWrite
($message, $newline);
156
}
157
}
158
165
abstract
public
function
doWrite
($message, $newline);
166
174
protected
function
format
($message)
175
{
176
$message = preg_replace_callback(
'#<([a-z][a-z0-9\-_=;]+)>#i'
, array($this,
'replaceStartStyle'
), $message);
177
178
return
preg_replace_callback(
'#</([a-z][a-z0-9\-_]*)?>#i'
, array($this,
'replaceEndStyle'
), $message);
179
}
180
184
protected
function
replaceStartStyle
($match)
185
{
186
if
(!$this->decorated) {
187
return
''
;
188
}
189
190
if
(isset(static::$styles[strtolower($match[1])])) {
191
$parameters = static::$styles[strtolower($match[1])];
192
}
else
{
193
// bg=blue;fg=red
194
if
(!preg_match_all(
'/([^=]+)=([^;]+)(;|$)/'
, strtolower($match[1]), $matches, PREG_SET_ORDER)) {
195
throw
new \InvalidArgumentException(sprintf(
'Unknown style "%s".'
, $match[1]));
196
}
197
198
$parameters = array();
199
foreach
($matches as $match) {
200
$parameters[$match[1]] = $match[2];
201
}
202
}
203
204
$codes = array();
205
206
if
(isset($parameters[
'fg'
])) {
207
$codes[] = static::$foreground[$parameters[
'fg'
]];
208
}
209
210
if
(isset($parameters[
'bg'
])) {
211
$codes[] = static::$background[$parameters[
'bg'
]];
212
}
213
214
foreach
(static::$options as $option => $value) {
215
if
(isset($parameters[$option]) && $parameters[$option]) {
216
$codes[] = $value;
217
}
218
}
219
220
return
"\033["
.implode(
';'
, $codes).
'm'
;
221
}
222
223
protected
function
replaceEndStyle
($match)
224
{
225
if
(!$this->decorated) {
226
return
''
;
227
}
228
229
return
"\033[0m"
;
230
}
231
}
Symfony\Component\Console\Output\Output
Definição
Output.php:26
Symfony\Component\Console\Output\Output\$options
static $options
Definição
Output.php:44
Symfony\Component\Console\Output\Output\$background
static $background
Definição
Output.php:46
Symfony\Component\Console\Output\Output\$decorated
$decorated
Definição
Output.php:36
Symfony\Component\Console\Output\Output\OUTPUT_PLAIN
const OUTPUT_PLAIN
Definição
Output.php:33
Symfony\Component\Console\Output\Output\setDecorated
setDecorated($decorated)
Definição
Output.php:76
Symfony\Component\Console\Output\Output\getVerbosity
getVerbosity()
Definição
Output.php:106
Symfony\Component\Console\Output\Output\$verbosity
$verbosity
Definição
Output.php:35
Symfony\Component\Console\Output\Output\$foreground
static $foreground
Definição
Output.php:45
Symfony\Component\Console\Output\Output\isDecorated
isDecorated()
Definição
Output.php:86
Symfony\Component\Console\Output\Output\VERBOSITY_VERBOSE
const VERBOSITY_VERBOSE
Definição
Output.php:29
Symfony\Component\Console\Output\Output\VERBOSITY_NORMAL
const VERBOSITY_NORMAL
Definição
Output.php:28
Symfony\Component\Console\Output\Output\writeln
writeln($messages, $type=0)
Definição
Output.php:117
Symfony\Component\Console\Output\Output\replaceEndStyle
replaceEndStyle($match)
Definição
Output.php:223
Symfony\Component\Console\Output\Output\setVerbosity
setVerbosity($level)
Definição
Output.php:96
Symfony\Component\Console\Output\Output\OUTPUT_NORMAL
const OUTPUT_NORMAL
Definição
Output.php:31
Symfony\Component\Console\Output\Output\$styles
static $styles
Definição
Output.php:38
Symfony\Component\Console\Output\Output\VERBOSITY_QUIET
const VERBOSITY_QUIET
Definição
Output.php:27
Symfony\Component\Console\Output\Output\__construct
__construct($verbosity=self::VERBOSITY_NORMAL, $decorated=null)
Definição
Output.php:54
Symfony\Component\Console\Output\Output\format
format($message)
Definição
Output.php:174
Symfony\Component\Console\Output\Output\setStyle
static setStyle($name, $options=array())
Definição
Output.php:66
Symfony\Component\Console\Output\Output\doWrite
doWrite($message, $newline)
Symfony\Component\Console\Output\Output\write
write($messages, $newline=false, $type=0)
Definição
Output.php:131
Symfony\Component\Console\Output\Output\replaceStartStyle
replaceStartStyle($match)
Definição
Output.php:184
Symfony\Component\Console\Output\Output\OUTPUT_RAW
const OUTPUT_RAW
Definição
Output.php:32
Symfony\Component\Console\Output\OutputInterface
Definição
OutputInterface.php:20
Symfony\Component\Console\Output
Definição
ConsoleOutput.php:3
classes
extensions
doctrine-dbal
Doctrine
Symfony
Component
Console
Output
Output.php
Gerado por
1.10.0