17
17
class OutputFormatterStyleStack
18
18
{
19
19
/**
20
- * @var OutputFormatterStyle []
20
+ * @var OutputFormatterStyleInterface []
21
21
*/
22
22
private $ styles ;
23
23
24
+ /**
25
+ * @var OutputFormatterStyleInterface
26
+ */
27
+ private $ emptyStyle ;
28
+
24
29
/**
25
30
* Constructor.
31
+ *
32
+ * @param \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface $emptyStyle
26
33
*/
27
- public function __construct ()
34
+ public function __construct (OutputFormatterStyleInterface $ emptyStyle = null )
28
35
{
36
+ $ this ->emptyStyle = $ emptyStyle ?: new OutputFormatterStyle ();
29
37
$ this ->reset ();
30
38
}
31
39
@@ -59,7 +67,7 @@ public function push(OutputFormatterStyleInterface $style)
59
67
public function pop (OutputFormatterStyleInterface $ style = null )
60
68
{
61
69
if (empty ($ this ->styles )) {
62
- return new OutputFormatterStyle () ;
70
+ return $ this -> emptyStyle ;
63
71
}
64
72
65
73
if (null === $ style ) {
@@ -85,9 +93,29 @@ public function pop(OutputFormatterStyleInterface $style = null)
85
93
public function getCurrent ()
86
94
{
87
95
if (empty ($ this ->styles )) {
88
- return new OutputFormatterStyle () ;
96
+ return $ this -> emptyStyle ;
89
97
}
90
98
91
99
return $ this ->styles [count ($ this ->styles )-1 ];
92
100
}
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
+ }
93
121
}
0 commit comments