Skip to content

Commit

Permalink
[console] Removed hardcoded empty style from styles stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfsimon committed Jun 5, 2012
1 parent f9aa6f7 commit 0ae5a45
Showing 1 changed file with 32 additions and 4 deletions.
Expand Up @@ -17,15 +17,23 @@
class OutputFormatterStyleStack
{
/**
* @var OutputFormatterStyle[]
* @var OutputFormatterStyleInterface[]
*/
private $styles;

/**
* @var OutputFormatterStyleInterface
*/
private $emptyStyle;

/**
* Constructor.
*
* @param \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface $emptyStyle
*/
public function __construct()
public function __construct(OutputFormatterStyleInterface $emptyStyle = null)
{
$this->emptyStyle = $emptyStyle ?: new OutputFormatterStyle();
$this->reset();
}

Expand Down Expand Up @@ -59,7 +67,7 @@ public function push(OutputFormatterStyleInterface $style)
public function pop(OutputFormatterStyleInterface $style = null)
{
if (empty($this->styles)) {
return new OutputFormatterStyle();
return $this->emptyStyle;
}

if (null === $style) {
Expand All @@ -85,9 +93,29 @@ public function pop(OutputFormatterStyleInterface $style = null)
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;
}
}

0 comments on commit 0ae5a45

Please sign in to comment.