From 49b968df67f0b469d4399695c15713a0001cd9d2 Mon Sep 17 00:00:00 2001 From: "ever.zet" Date: Sat, 12 Mar 2011 13:49:06 +0200 Subject: [PATCH 1/4] we need ability to get style parameters same way we set them with setStyle from last privatisation update $styles now private. So, user can set style with public setter (setStyle), but can't get this value later, which is very stupid behavior! --- src/Symfony/Component/Console/Output/Output.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Symfony/Component/Console/Output/Output.php b/src/Symfony/Component/Console/Output/Output.php index 349392643c..1c03bdc984 100644 --- a/src/Symfony/Component/Console/Output/Output.php +++ b/src/Symfony/Component/Console/Output/Output.php @@ -68,6 +68,22 @@ abstract class Output implements OutputInterface self::$styles[strtolower($name)] = $options; } + /** + * Gets style options from style with specified name. + * + * @param string $name + * + * @return array + */ + static public function getStyle($name) + { + if (!isset(self::$styles[strtolower($name)])) { + throw new \InvalidArgumentException('Undefined style: ' . $name); + } + + return self::$styles[strtolower($name)]; + } + /** * Sets the decorated flag. * From a809453416130078122401ff3cba6378a163cdb1 Mon Sep 17 00:00:00 2001 From: "ever.zet" Date: Sat, 12 Mar 2011 13:54:35 +0200 Subject: [PATCH 2/4] ability to define custom regex's for style placeholders sometimes, developers like me want to redefine style placeholders in their applications. From this patch, they can acchieve this from simple get...Regex() method redefine. --- .../Component/Console/Output/Output.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Output/Output.php b/src/Symfony/Component/Console/Output/Output.php index 1c03bdc984..52694272b6 100644 --- a/src/Symfony/Component/Console/Output/Output.php +++ b/src/Symfony/Component/Console/Output/Output.php @@ -180,6 +180,26 @@ abstract class Output implements OutputInterface */ abstract public function doWrite($message, $newline); + /** + * Gets regex for a style start. + * + * @return string + */ + protected function getStartStyleRegex() + { + return '#<([a-z][a-z0-9\-_=;]+)>#i'; + } + + /** + * Gets regex for a style end. + * + * @return string + */ + protected function getEndStyleRegex() + { + return '##i'; + } + /** * Formats a message according to the given styles. * @@ -189,9 +209,9 @@ abstract class Output implements OutputInterface */ protected function format($message) { - $message = preg_replace_callback('#<([a-z][a-z0-9\-_=;]+)>#i', array($this, 'replaceStartStyle'), $message); + $message = preg_replace_callback($this->getStartStyleRegex(), array($this, 'replaceStartStyle'), $message); - return preg_replace_callback('##i', array($this, 'replaceEndStyle'), $message); + return preg_replace_callback($this->getEndStyleRegex(), array($this, 'replaceEndStyle'), $message); } /** From d4d8576f93a688c887832eb6e01f185e3f79037e Mon Sep 17 00:00:00 2001 From: "ever.zet" Date: Sat, 12 Mar 2011 13:57:04 +0200 Subject: [PATCH 3/4] start => finish, begin => end. Mixing them is a bad choice. --- src/Symfony/Component/Console/Output/Output.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Output/Output.php b/src/Symfony/Component/Console/Output/Output.php index 52694272b6..2ac074b08c 100644 --- a/src/Symfony/Component/Console/Output/Output.php +++ b/src/Symfony/Component/Console/Output/Output.php @@ -185,7 +185,7 @@ abstract class Output implements OutputInterface * * @return string */ - protected function getStartStyleRegex() + protected function getBeginStyleRegex() { return '#<([a-z][a-z0-9\-_=;]+)>#i'; } @@ -209,7 +209,7 @@ abstract class Output implements OutputInterface */ protected function format($message) { - $message = preg_replace_callback($this->getStartStyleRegex(), array($this, 'replaceStartStyle'), $message); + $message = preg_replace_callback($this->getBeginStyleRegex(), array($this, 'replaceBeginStyle'), $message); return preg_replace_callback($this->getEndStyleRegex(), array($this, 'replaceEndStyle'), $message); } @@ -223,7 +223,7 @@ abstract class Output implements OutputInterface * * @throws \InvalidArgumentException When style is unknown */ - private function replaceStartStyle($match) + private function replaceBeginStyle($match) { if (!$this->decorated) { return ''; From dab8e5888f6fcde02f69cb2d48490070d7540105 Mon Sep 17 00:00:00 2001 From: "ever.zet" Date: Sat, 12 Mar 2011 13:59:51 +0200 Subject: [PATCH 4/4] if we moved definition under private area, than we need to use only public API for that, to be able to redefine it is subclasses --- src/Symfony/Component/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index b5b7e1b751..62a8fab9e2 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -235,7 +235,7 @@ class Application 'Options:', ); - foreach ($this->definition->getOptions() as $option) { + foreach ($this->getDefinition()->getOptions() as $option) { $messages[] = sprintf(' %-29s %s %s', '--'.$option->getName().'', $option->getShortcut() ? '-'.$option->getShortcut().'' : ' ',