From 9f30e42c16ad24f5fd4dc512d2a85ffb785e5c26 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 7 Feb 2011 03:03:02 +0100 Subject: [PATCH] added --debug/-d and --env/-d to console --- .../FrameworkBundle/Console/Application.php | 4 ++- .../Component/Console/Input/ArgvInput.php | 32 +++++++++++++++++++ .../Component/Console/Input/ArrayInput.php | 27 ++++++++++++++++ .../Console/Input/InputInterface.php | 12 +++++++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 118bbfaeb6..806bd1835e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -34,9 +34,11 @@ class Application extends BaseApplication { $this->kernel = $kernel; - parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName()); + parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' : '')); $this->definition->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.')); + $this->definition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev')); + $this->definition->addOption(new InputOption('--debug', '-d', InputOption::VALUE_NONE, 'Whether to run in debug mode.')); $this->kernel->boot(); diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 5662e5f69b..ddaeb2b99e 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -252,4 +252,36 @@ class ArgvInput extends Input return false; } + + /** + * Returns the value of a raw option (not parsed). + * + * This method is to be used to introspect the input parameters + * before it has been validated. It must be used carefully. + * + * @param string|array $values The value(s) to look for in the raw parameters (can be an array) + * + * @return mixed The option value + */ + public function getParameterOption(array $values, $default = false) + { + if (!is_array($values)) { + $values = array($values); + } + + $tokens = $this->tokens; + while ($token = array_shift($tokens)) { + foreach ($values as $value) { + if (0 === strpos($token, $value)) { + if (false !== $pos = strpos($token, '=')) { + return substr($token, $pos + 1); + } else { + return array_shift($this->tokens); + } + } + } + } + + return $default; + } } diff --git a/src/Symfony/Component/Console/Input/ArrayInput.php b/src/Symfony/Component/Console/Input/ArrayInput.php index e9572d71ed..407f3f2432 100644 --- a/src/Symfony/Component/Console/Input/ArrayInput.php +++ b/src/Symfony/Component/Console/Input/ArrayInput.php @@ -82,6 +82,33 @@ class ArrayInput extends Input return false; } + /** + * Returns the value of a raw option (not parsed). + * + * This method is to be used to introspect the input parameters + * before it has been validated. It must be used carefully. + * + * @param string|array $values The value(s) to look for in the raw parameters (can be an array) + * + * @return mixed The option value + */ + public function getParameterOption(array $values, $default = false) + { + if (!is_array($values)) { + $values = array($values); + } + + foreach ($this->parameters as $k => $v) { + if (is_int($k) && in_array($v, $values)) { + return true; + } elseif (in_array($k, $values)) { + return $v; + } + } + + return $default; + } + /** * Processes command line arguments. */ diff --git a/src/Symfony/Component/Console/Input/InputInterface.php b/src/Symfony/Component/Console/Input/InputInterface.php index 1027507ff7..3fd6800c2a 100644 --- a/src/Symfony/Component/Console/Input/InputInterface.php +++ b/src/Symfony/Component/Console/Input/InputInterface.php @@ -37,6 +37,18 @@ interface InputInterface */ function hasParameterOption($value); + /** + * Returns the value of a raw option (not parsed). + * + * This method is to be used to introspect the input parameters + * before it has been validated. It must be used carefully. + * + * @param string|array $values The value(s) to look for in the raw parameters (can be an array) + * + * @return mixed The option value + */ + function getParameterOption(array $values, $default = false); + /** * Binds the current Input instance with the given arguments and options. *