Parcourir la source

[Console] added __get() to Command to have shorter and more readable code in commands

Fabien Potencier il y a 15 ans
Parent
commit
d229ce584f
1 fichiers modifiés avec 14 ajouts et 0 suppressions
  1. 14 0
      src/Symfony/Components/Console/Command/Command.php

+ 14 - 0
src/Symfony/Components/Console/Command/Command.php

@@ -423,6 +423,20 @@ class Command
     return $this->application->getHelperSet()->get($name);
   }
 
+  /**
+   * Gets a helper instance by name.
+   *
+   * @param string $name The helper name
+   *
+   * @return mixed The helper value
+   *
+   * @throws \InvalidArgumentException if the helper is not defined
+   */
+  public function __get($name)
+  {
+    return $this->application->getHelperSet()->get($name);
+  }
+
   /**
    * Returns a text representation of the command.
    *