@@ -15,6 +15,11 @@ first argument, an :class:`Symfony\\Component\\Console\\Output\\OutputInterface`
15
15
instance as the second argument and a
16
16
:class: `Symfony\\ Component\\ Console\\ Question\\ Question ` as last argument.
17
17
18
+ .. note ::
19
+
20
+ As an alternative, consider using the
21
+ :ref: `SymfonyStyle <symfony-style-questions >` to ask questions.
22
+
18
23
Asking the User for Confirmation
19
24
--------------------------------
20
25
@@ -82,9 +87,9 @@ if you want to know a bundle name, you can add this to your command::
82
87
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
83
88
84
89
$bundleName = $helper->ask($input, $output, $question);
85
-
90
+
86
91
// ... do something with the bundleName
87
-
92
+
88
93
return Command::SUCCESS;
89
94
}
90
95
@@ -120,7 +125,7 @@ from a predefined list::
120
125
$output->writeln('You have just selected: '.$color);
121
126
122
127
// ... do something with the color
123
-
128
+
124
129
return Command::SUCCESS;
125
130
}
126
131
@@ -162,7 +167,7 @@ this use :method:`Symfony\\Component\\Console\\Question\\ChoiceQuestion::setMult
162
167
163
168
$colors = $helper->ask($input, $output, $question);
164
169
$output->writeln('You have just selected: ' . implode(', ', $colors));
165
-
170
+
166
171
return Command::SUCCESS;
167
172
}
168
173
@@ -191,9 +196,9 @@ will be autocompleted as the user types::
191
196
$question->setAutocompleterValues($bundles);
192
197
193
198
$bundleName = $helper->ask($input, $output, $question);
194
-
199
+
195
200
// ... do something with the bundleName
196
-
201
+
197
202
return Command::SUCCESS;
198
203
}
199
204
@@ -230,9 +235,9 @@ provide a callback function to dynamically generate suggestions::
230
235
$question->setAutocompleterCallback($callback);
231
236
232
237
$filePath = $helper->ask($input, $output, $question);
233
-
238
+
234
239
// ... do something with the filePath
235
-
240
+
236
241
return Command::SUCCESS;
237
242
}
238
243
@@ -254,9 +259,9 @@ You can also specify if you want to not trim the answer by setting it directly w
254
259
$question->setTrimmable(false);
255
260
// if the users inputs 'elsa ' it will not be trimmed and you will get 'elsa ' as value
256
261
$name = $helper->ask($input, $output, $question);
257
-
262
+
258
263
// ... do something with the name
259
-
264
+
260
265
return Command::SUCCESS;
261
266
}
262
267
@@ -285,9 +290,9 @@ the response to a question should allow multiline answers by passing ``true`` to
285
290
$question->setMultiline(true);
286
291
287
292
$answer = $helper->ask($input, $output, $question);
288
-
293
+
289
294
// ... do something with the answer
290
-
295
+
291
296
return Command::SUCCESS;
292
297
}
293
298
@@ -313,9 +318,9 @@ convenient for passwords::
313
318
$question->setHiddenFallback(false);
314
319
315
320
$password = $helper->ask($input, $output, $question);
316
-
321
+
317
322
// ... do something with the password
318
-
323
+
319
324
return Command::SUCCESS;
320
325
}
321
326
@@ -347,7 +352,7 @@ convenient for passwords::
347
352
QuestionHelper::disableStty();
348
353
349
354
// ...
350
-
355
+
351
356
return Command::SUCCESS;
352
357
}
353
358
@@ -376,9 +381,9 @@ method::
376
381
});
377
382
378
383
$bundleName = $helper->ask($input, $output, $question);
379
-
384
+
380
385
// ... do something with the bundleName
381
-
386
+
382
387
return Command::SUCCESS;
383
388
}
384
389
@@ -420,9 +425,9 @@ method::
420
425
$question->setMaxAttempts(2);
421
426
422
427
$bundleName = $helper->ask($input, $output, $question);
423
-
428
+
424
429
// ... do something with the bundleName
425
-
430
+
426
431
return Command::SUCCESS;
427
432
}
428
433
@@ -482,9 +487,9 @@ You can also use a validator with a hidden question::
482
487
$question->setMaxAttempts(20);
483
488
484
489
$password = $helper->ask($input, $output, $question);
485
-
490
+
486
491
// ... do something with the password
487
-
492
+
488
493
return Command::SUCCESS;
489
494
}
490
495
0 commit comments