diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php index 3f88e0a758..32374524f2 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php @@ -17,15 +17,23 @@ namespace Symfony\Component\Console\Formatter; class OutputFormatterStyleStack { /** - * @var OutputFormatterStyle[] + * @var OutputFormatterStyleInterface[] */ private $styles; /** - * Constructor. + * @var OutputFormatterStyleInterface */ - public function __construct() + private $emptyStyle; + + /** + * Constructor. + * + * @param \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface $emptyStyle + */ + public function __construct(OutputFormatterStyleInterface $emptyStyle = null) { + $this->emptyStyle = $emptyStyle ?: new OutputFormatterStyle(); $this->reset(); } @@ -59,7 +67,7 @@ class OutputFormatterStyleStack public function pop(OutputFormatterStyleInterface $style = null) { if (empty($this->styles)) { - return new OutputFormatterStyle(); + return $this->emptyStyle; } if (null === $style) { @@ -85,9 +93,29 @@ class OutputFormatterStyleStack public function getCurrent() { if (empty($this->styles)) { - return new OutputFormatterStyle(); + return $this->emptyStyle; } return $this->styles[count($this->styles)-1]; } + + /** + * @param \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface $emptyStyle + * + * @return \Symfony\Component\Console\Formatter\OutputFormatterStyleStack + */ + public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) + { + $this->emptyStyle = $emptyStyle; + + return $this; + } + + /** + * @return \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface + */ + public function getEmptyStyle() + { + return $this->emptyStyle; + } }