symfony/symfony — pull request #5752 by nfx (2012-10-14 21:46:02+00:00)
Title: [Console] Ask for list of values

There are some cases, when CLI application wants to get a list of values from a user interactively. So this functionality could be helpful for that.

$list = $this->getHelper('dialog')->askForList($output, 'Give me a list of numbers', function($i) {
if(!is_numeric($i)) {
throw new \InvalidArgumentException('Value is not number');
}

return $i;
});
var_dump($list);

In order to get list from user simple call to askForList is required. Optional filter could be provided to validate and filter received value. Example flow would look like the following:

$ app/console pugooroo:ask-for-list
Give me a list of numbers
> 1
> 2
> fsf
Value is not number
> 4
>
array(3) {
[0] =>
string(1) "1"
[1] =>
string(1) "2"
[2] =>
string(1) "4"
}

Still needs comments, as this method has similarities with askAndValidate, which has validation behaviour semantically different to Validator component, so i've decided not to re-use it and name a filter concept. If receive approval - will add unit tests and further documentation.