4
4
Dialog Helper
5
5
=============
6
6
7
- The Dialog Helper provides functions to ask the user for more information.
8
-
9
- The DialogHelper is included in the default helper set, which you can get
7
+ The Dialog Helper provides functions to ask the user for more information.
8
+ It is included in the default helper set, which you can get
10
9
by calling :method: `Symfony\\ Component\\ Console\\ Command\\ Command::getHelperSet `::
11
10
12
11
$dialog = $this->getHelperSet()->get('dialog');
@@ -30,16 +29,16 @@ the following to your command::
30
29
return;
31
30
}
32
31
33
- In this case, the user will be asked "Continue with this action", and unless
34
- they answer with ``y ``, the task will stop running . The third argument to
35
- ``askConfirmation `` is the default value to return if the user doesn't enter
36
- any input.
32
+ In this case, the user will be asked "Continue with this action", and will return
33
+ `` true `` if the user answers with ``y `` or false in any other case . The third
34
+ argument to ``askConfirmation `` is the default value to return if the user doesn't
35
+ enter any input.
37
36
38
37
Asking the User for information
39
38
-------------------------------
40
39
41
40
You can also ask question with more than a simple yes/no answer. For instance,
42
- you want to know a bundle name, you can add this to your command::
41
+ if you want to know a bundle name, you can add this to your command::
43
42
44
43
// ...
45
44
$bundle = $dialog->ask(
@@ -49,8 +48,8 @@ you want to know a bundle name, you can add this to your command::
49
48
);
50
49
51
50
The user will be asked "Please enter the name of the bundle". They can type
52
- some name or if they leave it empty the default value (`` AcmeDemoBundle `` here)
53
- is used. This value will be returned.
51
+ some name which will be returned by the `` ask `` method. If they leave it empty
52
+ the default value (`` AcmeDemoBundle `` here) is returned.
54
53
55
54
Validating the answer
56
55
---------------------
@@ -87,10 +86,12 @@ This methods has 2 new arguments, the full signature is::
87
86
)
88
87
89
88
The ``$validator `` is a callback which handles the validation. It should
90
- throw an exception if there is something wrong. The exception message displayed
89
+ throw an exception if there is something wrong. The exception message is displayed
91
90
in the console, so it is a good practice to put some usefull information
92
91
in it.
93
92
94
93
You can set the max number of times to ask in the ``$attempts `` argument.
95
94
If we reach this max number it will use the default value, which is given
96
- in the last argument. This is ``false `` by default, which means it is infinite.
95
+ in the last argument. Using ``false `` means the amount of attempts is infinite.
96
+ The user will be asked as long as he provides an invalid answer and will only
97
+ be able to proceed if his input is valid.
0 commit comments