8000 merged branch Tobion/console-nulloutput (PR #8037) · symfony/symfony@b027c92 · GitHub
[go: up one dir, main page]

Skip to content

Commit b027c92

Browse files
committed
merged branch Tobion/console-nulloutput (PR #8037)
This PR was merged into the master branch. Discussion ---------- [Console] fix Output classes Please see commits. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT Commits ------- 940b788 [Console] use inheritdoc for Output classes bd61b92 [Console] fix phpdoc of Output classes (esp. regarding the new verbosities) 9dcc9fa [Console] fix abstract Output class that fasly claims to support guessing of decorated variable. 2628d88 [Console] the default type value should use the constant in OutputInterface::write ee0cc40 [Console] fix NullOutput a290f87 [Console] fix test for NullOutput that does not print anything and add a failing test for verbosity
2 parents 89c2591 + 940b788 commit b027c92

File tree

7 files changed

+140
-87
lines changed

7 files changed

+140
-87
lines changed

src/Symfony/Component/Console/Output/ConsoleOutput.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
3636
/**
3737
* Constructor.
3838
*
39-
* @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL,
40-
* self::VERBOSITY_VERBOSE)
41-
* @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
42-
* @param OutputFormatterInterface $formatter Output formatter instance
39+
* @param integer $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
40+
* @param Boolean|null $decorated Whether to decorate messages (null for auto-guessing)
41+
* @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
4342
*
4443
* @api
4544
*/
@@ -55,32 +54,44 @@ public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = nu
5554
$this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $formatter);
5655
}
5756

57+
/**
58+
* {@inheritdoc}
59+
*/
5860
public function setDecorated($decorated)
5961
{
6062
parent::setDecorated($decorated);
6163
$this->stderr->setDecorated($decorated);
6264
}
6365

66+
/**
67+
* {@inheritdoc}
68+
*/
6469
public function setFormatter(OutputFormatterInterface $formatter)
6570
{
6671
parent::setFormatter($formatter);
6772
$this->stderr->setFormatter($formatter);
6873
}
6974

75+
/**
76+
* {@inheritdoc}
77+
*/
7078
public function setVerbosity($level)
7179
{
7280
parent::setVerbosity($level);
7381
$this->stderr->setVerbosity($level);
7482
}
7583

7684
/**
77-
* @return OutputInterface
85+
* {@inheritdoc}
7886
*/
7987
public function getErrorOutput()
8088
{
8189
return $this->stderr;
8290
}
8391

92+
/**
93+
* {@inheritdoc}
94+
*/
8495
public function setErrorOutput(OutputInterface $error)
8596
{
8697
$this->stderr = $error;

src/Symfony/Component/Console/Output/ConsoleOutputInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@
2222
interface ConsoleOutputInterface extends OutputInterface
2323
{
2424
/**
25+
* Gets the OutputInterface for errors.
26+
*
2527
* @return OutputInterface
2628
*/
2729
public function getErrorOutput();
2830

31+
/**
32+
* Sets the OutputInterface used for errors.
33+
*
34+
* @param OutputInterface $error
35+
*/
2936
public function setErrorOutput(OutputInterface $error);
3037
}

src/Symfony/Component/Console/Output/NullOutput.php

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,83 @@
1111

1212
namespace Symfony\Component\Console\Output;
1313

14+
use Symfony\Component\Console\Formatter\OutputFormatter;
15+
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
16+
1417
/**
1518
* NullOutput suppresses all output.
1619
*
1720
* $output = new NullOutput();
1821
*
1922
* @author Fabien Potencier <fabien@symfony.com>
23+
* @author Tobias Schultze <http://tobion.de>
2024
*
2125
* @api
2226
*/
23-
class NullOutput extends Output
27+
class NullOutput implements OutputInterface
2428
{
2529
/**
26-
* Writes a message to the output.
27-
*
28-
* @param string $message A message to write to the output
29-
* @param Boolean $newline Whether to add a newline or not
30+
* {@inheritdoc}
31+
*/
32+
public function setFormatter(OutputFormatterInterface $formatter)
33+
{
34+
// do nothing
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function getFormatter()
41+
{
42+
// to comply with the interface we must return a OutputFormatterInterface
43+
return new OutputFormatter();
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function setDecorated($decorated)
50+
{
51+
// do nothing
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function isDecorated()
58+
{
59+
return false;
60+
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
public function setVerbosity($level)
66+
{
67+
// do nothing
68+
}
69+
70+
/**
71+
* {@inheritdoc}
72+
*/
73+
public function getVerbosity()
74+
{
75+
return self::VERBOSITY_QUIET;
76+
}
77+
78+
/**
79+
* {@inheritdoc}
80+
*/
81+
public function writeln($messages, $type = self::OUTPUT_NORMAL)
82+
{
83+
// do nothing
84+
}
85+
86+
/**
87+
* {@inheritdoc}
3088
*/
31-
protected function doWrite($message, $newline)
89+
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
3290
{
91+
// do nothing
3392
}
3493
}

src/Symfony/Component/Console/Output/Output.php

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
/**
1818
* Base class for output classes.
1919
*
20-
* There are three levels of verbosity:
20+
* There are five levels of verbosity:
2121
*
22-
* * normal: no option passed (normal output - information)
23-
* * verbose: -v (more output - debug)
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)
2426
* * quiet: -q (no output)
2527
*
2628
* @author Fabien Potencier <fabien@symfony.com>
@@ -35,116 +37,79 @@ abstract class Output implements OutputInterface
3537
/**
3638
* Constructor.
3739
*
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
40+
* @param integer $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
41+
* @param Boolean $decorated Whether to decorate messages
42+
* @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
4143
*
4244
* @api
4345
*/
44-
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
46+
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null)
4547
{
4648
$this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
4749
$this->formatter = null === $formatter ? new OutputFormatter() : $formatter;
48-
$this->formatter->setDecorated((Boolean) $decorated);
50+
$this->formatter->setDecorated($decorated);
4951
}
5052

5153
/**
52-
* Sets output formatter.
53-
*
54-
* @param OutputFormatterInterface $formatter
55-
*
56-
* @api
54+
* {@inheritdoc}
5755
*/
5856
public function setFormatter(OutputFormatterInterface $formatter)
5957
{
6058
$this->formatter = $formatter;
6159
}
6260

6361
/**
64-
* Returns current output formatter instance.
65-
*
66-
* @return OutputFormatterInterface
67-
*
68-
* @api
62+
* {@inheritdoc}
6963
*/
7064
public function getFormatter()
7165
{
7266
return $this->formatter;
7367
}
7468

7569
/**
76-
* Sets the decorated flag.
77-
*
78-
* @param Boolean $decorated Whether to decorate the messages or not
79-
*
80-
* @api
70+
* {@inheritdoc}
8171
*/
8272
public function setDecorated($decorated)
8373
{
84-
$this->formatter->setDecorated((Boolean) $decorated);
74+
$this->formatter->setDecorated($decorated);
8575
}
8676

8777
/**
88-
* Gets the decorated flag.
89-
*
90-
* @return Boolean true if the output will decorate messages, false otherwise
91-
*
92-
* @api
78+
* {@inheritdoc}
9379
*/
9480
public function isDecorated()
9581
{
9682
return $this->formatter->isDecorated();
9783
}
9884

9985
/**
100-
* Sets the verbosity of the output.
101-
*
102-
* @param integer $level The level of verbosity
103-
*
104-
* @api
86+
* {@inheritdoc}
10587
*/
10688
public function setVerbosity($level)
10789
{
10890
$this->verbosity = (int) $level;
10991
}
11092

11193
/**
112-
* Gets the current verbosity of the output.
113-
*
114-
* @return integer The current level of verbosity
115-
*
116-
* @api
94+
* {@inheritdoc}
11795
*/
11896
public function getVerbosity()
11997
{
12098
return $this->verbosity;
12199
}
122100

123101
/**
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 or a single string
127-
* @param integer $type The type of output
128-
*
129-
* @api
102+
* {@inheritdoc}
130103
*/
131-
public function writeln($messages, $type = 0)
104+
public function writeln($messages, $type = self::OUTPUT_NORMAL)
132105
{
133106
$this->write($messages, true, $type);
134107
}
135108

136109
/**
137-
* Writes a message to the output.
138-
*
139-
* @param string|array $messages The message as an array of lines or 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
144-
*
145-
* @api
110+
* {@inheritdoc}
146111
*/
147-
public function write($messages, $newline = false, $type = 0)
112+
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
148113
{
149114
if (self::VERBOSITY_QUIET === $this->verbosity) {
150115
return;

src/Symfony/Component/Console/Output/OutputInterface.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,31 @@ interface OutputInterface
3636
* Writes a message to the output.
3737
*
3838
* @param string|array $messages The message as an array of lines or a single string
39-
* @param Boolean $newline Whether to add a newline or not
40-
* @param integer $type The type of output (0: normal, 1: raw, 2: plain)
39+
* @param Boolean $newline Whether to add a newline
40+
* @param integer $type The type of output (one of the OUTPUT constants)
4141
*
4242
* @throws \InvalidArgumentException When unknown output type is given
4343
*
4444
* @api
4545
*/
46-
public function write($messages, $newline = false, $type = 0);
46+
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL);
4747

4848
/**
4949
* Writes a message to the output and adds a newline at the end.
5050
*
5151
* @param string|array $messages The message as an array of lines of a single string
52-
* @param integer $type The type of output (0: normal, 1: raw, 2: plain)
52+
* @param integer $type The type of output (one of the OUTPUT constants)
53+
*
54+
* @throws \InvalidArgumentException When unknown output type is given
5355
*
5456
* @api
5557
*/
56-
public function writeln($messages, $type = 0);
58+
public function writeln($messages, $type = self::OUTPUT_NORMAL);
5759

5860
/**
5961
* Sets the verbosity of the output.
6062
*
61-
* @param integer $level The level of verbosity
63+
* @param integer $level The level of verbosity (one of the VERBOSITY constants)
6264
*
6365
* @api
6466
*/
@@ -67,7 +69,7 @@ public function setVerbosity($level);
6769
/**
6870
* Gets the current verbosity of the output.
6971
*
70-
* @return integer The current level of verbosity
72+
* @return integer The current level of verbosity (one of the VERBOSITY constants)
7173
*
7274
* @api
7375
*/
@@ -76,7 +78,7 @@ public function getVerbosity();
7678
/**
7779
* Sets the decorated flag.
7880
*
79-
* @param Boolean $decorated Whether to decorate the messages or not
81+
* @param Boolean $decorated Whether to decorate the messages
8082
*
8183
* @api
8284
*/

0 commit comments

Comments
 (0)
0