From 0ae5a452825f548eda4df76b2aa676f5b2892b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Tue, 5 Jun 2012 05:21:33 +0200 Subject: [PATCH 1/3] [console] Removed hardcoded empty style from styles stack. --- .../Formatter/OutputFormatterStyleStack.php | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) 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; + } } From c80e156f96b43ec7415592bfd1c61985e7695ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Tue, 5 Jun 2012 05:22:08 +0200 Subject: [PATCH 2/3] [console] Added style stack getter in formatter. --- .../Component/Console/Formatter/OutputFormatter.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php index 554fd6ca44..237d004771 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php @@ -138,6 +138,14 @@ class OutputFormatter implements OutputFormatterInterface return preg_replace_callback(self::FORMAT_PATTERN, array($this, 'replaceStyle'), $message); } + /** + * @return OutputFormatterStyleStack + */ + public function getStyleStack() + { + return $this->styleStack; + } + /** * Replaces style of the output. * From 5f328deed4441fba14876a69aa5e36afe11592ab Mon Sep 17 00:00:00 2001 From: "jeanfrancois.simon" Date: Tue, 5 Jun 2012 10:51:09 +0200 Subject: [PATCH 3/3] [console] Fixed docblock. --- .../Console/Formatter/OutputFormatterStyleStack.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php index 32374524f2..5915023c62 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php @@ -29,7 +29,7 @@ class OutputFormatterStyleStack /** * Constructor. * - * @param \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface $emptyStyle + * @param OutputFormatterStyleInterface $emptyStyle */ public function __construct(OutputFormatterStyleInterface $emptyStyle = null) { @@ -100,9 +100,9 @@ class OutputFormatterStyleStack } /** - * @param \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface $emptyStyle + * @param OutputFormatterStyleInterface $emptyStyle * - * @return \Symfony\Component\Console\Formatter\OutputFormatterStyleStack + * @return OutputFormatterStyleStack */ public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) { @@ -112,7 +112,7 @@ class OutputFormatterStyleStack } /** - * @return \Symfony\Component\Console\Formatter\OutputFormatterStyleInterface + * @return OutputFormatterStyleInterface */ public function getEmptyStyle() {