Skip to content

Commit 0ae5a45

Browse files
committed
[console] Removed hardcoded empty style from styles stack.
1 parent f9aa6f7 commit 0ae5a45

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717
class OutputFormatterStyleStack
1818
{
1919
/**
20-
* @var OutputFormatterStyle[]
20+
* @var OutputFormatterStyleInterface[]
2121
*/
2222
private $styles;
2323

24+
/**
25+
* @var OutputFormatterStyleInterface
26+
*/
27+
private $emptyStyle;
28+
2429
/**
2530
* Constructor.
31+
*
32+
* @param \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface $emptyStyle
2633
*/
27-
public function __construct()
34+
public function __construct(OutputFormatterStyleInterface $emptyStyle = null)
2835
{
36+
$this->emptyStyle = $emptyStyle ?: new OutputFormatterStyle();
2937
$this->reset();
3038
}
3139

@@ -59,7 +67,7 @@ public function push(OutputFormatterStyleInterface $style)
5967
public function pop(OutputFormatterStyleInterface $style = null)
6068
{
6169
if (empty($this->styles)) {
62-
return new OutputFormatterStyle();
70+
return $this->emptyStyle;
6371
}
6472

6573
if (null === $style) {
@@ -85,9 +93,29 @@ public function pop(OutputFormatterStyleInterface $style = null)
8593
public function getCurrent()
8694
{
8795
if (empty($this->styles)) {
88-
return new OutputFormatterStyle();
96+
return $this->emptyStyle;
8997
}
9098

9199
return $this->styles[count($this->styles)-1];
92100
}
101+
102+
/**
103+
* @param \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface $emptyStyle
104+
*
105+
* @return \Symfony\Component\Console\Formatter\OutputFormatterStyleStack
106+
*/
107+
public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle)
108+
{
109+
$this->emptyStyle = $emptyStyle;
110+
111+
return $this;
112+
}
113+
114+
/**
115+
* @return \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface
116+
*/
117+
public function getEmptyStyle()
118+
{
119+
return $this->emptyStyle;
120+
}
93121
}

0 commit comments

Comments
 (0)