@@ -287,6 +287,76 @@ if you needed to know the name of something, you might do the following::
287287 'foo'
288288 );
289289
290+ .. versionadded :: 2.2
291+ The ``askHiddenResponse `` method was added in Symfony 2.2.
292+
293+ You can also ask question and hide the response. This is particularly
294+ convenient for passwords::
295+
296+ $dialog = $this->getHelperSet()->get('dialog');
297+ $password = $dialog->askHiddenResponse(
298+ $output,
299+ 'What is the database password ?',
300+ false
301+ );
302+
303+ .. caution ::
304+
305+ When you ask an hidden response, Symfony will use either a binary, change
306+ stty mode or use another trick to hide the response. If none is available,
307+ it will fallback on the classic question unless you pass ``false `` as the
308+ third argument like in the example above. In this case, a RuntimeException
309+ would be thrown.
310+
311+ Ask and validate response
312+ -------------------------
313+
314+ You can easily ask question and validate response with built-in methods::
315+
316+ $dialog = $this->getHelperSet()->get('dialog');
317+
318+ $validator = function ($value) {
319+ if (trim($value) == '') {
320+ throw new \Exception('The value can not be empty');
321+ }
322+ }
323+
324+ $password = $dialog->askAndValidate(
325+ $output,
326+ 'Please enter the name of the widget',
327+ $validator,
328+ 20,
329+ 'foo'
330+ );
331+
332+ The validation callback can be any callable PHP function, the fourth argument is
333+ the maximum number of attempts, set it to ``false `` for unlimited attempts. The
334+ fifth argument is the default value.
335+
336+ .. versionadded :: 2.2
337+ The ``askHiddenResponseAndValidate `` method was added in Symfony 2.2.
338+
339+ You can also ask and validate hidden response::
340+
341+ $dialog = $this->getHelperSet()->get('dialog');
342+
343+ $validator = function ($value) {
344+ if (trim($value) == '') {
345+ throw new \Exception('The password can not be empty');
346+ }
347+ }
348+
349+ $password = $dialog->askHiddenResponseAndValidate(
350+ $output,
351+ 'Please enter the name of the widget',
352+ $validator,
353+ 20,
354+ false
355+ );
356+
357+ If you want to fallback on classic question in case hidden response can not be
358+ provided, pass true as fifth argument.
359+
290360Displaying a Progress Bar
291361-------------------------
292362
@@ -310,7 +380,7 @@ pass it a total number of units, and advance the progress as your command execut
310380
311381 // advance the progress bar 1 unit
312382 $progress->advance();
313- }
383+ }
314384
315385 $progress->finish();
316386
@@ -346,7 +416,7 @@ To see other available options, check the API documentation for
346416 to a high number. For example, if you're iterating over a large number
347417 of items, consider a smaller "step" number that updates on only some
348418 iterations::
349-
419+
350420 $progress->start($output, 500);
351421 $i = 0;
352422 while ($i++ < 50000) {
0 commit comments