[Console] added some explanation on how DialogHelper::askAndValidate works

This commit is contained in:
Fabien Potencier 2011-05-17 10:26:33 +02:00
parent 02e77ec4e3
commit 6308f93c64

View File

@ -70,16 +70,20 @@ class DialogHelper extends Helper
/** /**
* Asks for a value and validates the response. * Asks for a value and validates the response.
* *
* The validator receives the data to validate. It must return the
* validated data when the data is valid and throw an exception
* otherwise.
*
* @param OutputInterface $output * @param OutputInterface $output
* @param string|array $question * @param string|array $question
* @param Closure $validator * @param callback $validator A PHP callback
* @param integer $attempts Max number of times to ask before giving up (false by default, which means infinite) * @param integer $attempts Max number of times to ask before giving up (false by default, which means infinite)
* *
* @return mixed * @return mixed
* *
* @throws \Exception When any of the validator returns an error * @throws \Exception When any of the validator returns an error
*/ */
public function askAndValidate(OutputInterface $output, $question, \Closure $validator, $attempts = false) public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$error = null; $error = null;
@ -91,7 +95,7 @@ class DialogHelper extends Helper
$value = $this->ask($output, $question, null); $value = $this->ask($output, $question, null);
try { try {
return $validator($value); return call_user_func($validator, $value));
} catch (\Exception $error) { } catch (\Exception $error) {
} }
} }