Skip to content

Commit

Permalink
[Console] added the possibility to pass a default value for DialodHel…
Browse files Browse the repository at this point in the history
…per::askAndValidate()
  • Loading branch information
fabpot committed May 20, 2011
1 parent fed6dc9 commit 5ad2ff0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Symfony/Component/Console/Helper/DialogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DialogHelper extends Helper
public function ask(OutputInterface $output, $question, $default = null)
{
// @codeCoverageIgnoreStart
$output->writeln($question);
$output->write($question);

$ret = trim(fgets(STDIN));

Expand Down Expand Up @@ -78,12 +78,13 @@ public function askConfirmation(OutputInterface $output, $question, $default = t
* @param string|array $question
* @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 string $default The default answer if none is given by the user
*
* @return mixed
*
* @throws \Exception When any of the validator returns an error
*/
public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false)
public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null)
{
// @codeCoverageIgnoreStart
$error = null;
Expand All @@ -92,7 +93,7 @@ public function askAndValidate(OutputInterface $output, $question, $validator, $
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
}

$value = $this->ask($output, $question, null);
$value = $this->ask($output, $question, $default);

try {
return call_user_func($validator, $value);
Expand Down

0 comments on commit 5ad2ff0

Please sign in to comment.