Explorar o código

Merge remote branch 'everzet/console-privatisation-errors'

* everzet/console-privatisation-errors:
  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
  start => finish, begin => end. Mixing them is a bad choice.
  ability to define custom regex's for style placeholders
  we need ability to get style parameters same way we set them with setStyle
Fabien Potencier %!s(int64=14) %!d(string=hai) anos
pai
achega
dcc1948fb6

+ 1 - 1
src/Symfony/Component/Console/Application.php

@@ -235,7 +235,7 @@ class Application
             '<comment>Options:</comment>',
         );
 
-        foreach ($this->definition->getOptions() as $option) {
+        foreach ($this->getDefinition()->getOptions() as $option) {
             $messages[] = sprintf('  %-29s %s %s',
                 '<info>--'.$option->getName().'</info>',
                 $option->getShortcut() ? '<info>-'.$option->getShortcut().'</info>' : '  ',

+ 39 - 3
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.
      *
@@ -164,6 +180,26 @@ abstract class Output implements OutputInterface
      */
     abstract public function doWrite($message, $newline);
 
+    /**
+     * Gets regex for a style start.
+     *
+     * @return  string
+     */
+    protected function getBeginStyleRegex()
+    {
+        return '#<([a-z][a-z0-9\-_=;]+)>#i';
+    }
+
+    /**
+     * Gets regex for a style end.
+     *
+     * @return  string
+     */
+    protected function getEndStyleRegex()
+    {
+        return '#</([a-z][a-z0-9\-_]*)?>#i';
+    }
+
     /**
      * Formats a message according to the given styles.
      *
@@ -173,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->getBeginStyleRegex(), array($this, 'replaceBeginStyle'), $message);
 
-        return preg_replace_callback('#</([a-z][a-z0-9\-_]*)?>#i', array($this, 'replaceEndStyle'), $message);
+        return preg_replace_callback($this->getEndStyleRegex(), array($this, 'replaceEndStyle'), $message);
     }
 
     /**
@@ -187,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 '';