@@ -2,11 +2,9 @@ Question Helper
2
2
===============
3
3
4
4
The :class: `Symfony\\ Component\\ Console\\ Helper\\ QuestionHelper ` provides
5
- functions to ask the user for more information. It is included in the default
6
- helper set and you can get it by calling
7
- :method: `Symfony\\ Component\\ Console\\ Command\\ Command::getHelper `::
5
+ functions to ask the user for more information::
8
6
9
- $helper = $this->getHelper('question' );
7
+ $helper = new QuestionHelper( );
10
8
11
9
The Question Helper has a single method
12
10
:method: `Symfony\\ Component\\ Console\\ Helper\\ QuestionHelper::ask ` that needs an
@@ -38,7 +36,7 @@ the following to your command::
38
36
{
39
37
public function __invoke(InputInterface $input, OutputInterface $output): int
40
38
{
41
- $helper = $this->getHelper('question' );
39
+ $helper = new QuestionHelper( );
42
40
$question = new ConfirmationQuestion('Continue with this action?', false);
43
41
44
42
if (!$helper->ask($input, $output, $question)) {
@@ -91,7 +89,7 @@ if you want to know a bundle name, you can add this to your command::
91
89
use Symfony\Component\Console\Question\Question;
92
90
93
91
// ...
94
- public function execute (InputInterface $input, OutputInterface $output): int
92
+ public function __invoke (InputInterface $input, OutputInterface $output): int
95
93
{
96
94
// ...
97
95
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
@@ -121,10 +119,10 @@ but ``red`` could be set instead (could be more explicit)::
121
119
use Symfony\Component\Console\Question\ChoiceQuestion;
122
120
123
121
// ...
124
- public function execute (InputInterface $input, OutputInterface $output): int
122
+ public function __invoke (InputInterface $input, OutputInterface $output): int
125
123
{
126
124
// ...
127
- $helper = $this->getHelper('question' );
125
+ $helper = new QuestionHelper( );
128
126
$question = new ChoiceQuestion(
129
127
'Please select your favorite color (defaults to red)',
130
128
// choices can also be PHP objects that implement __toString() method
@@ -184,10 +182,10 @@ this use :method:`Symfony\\Component\\Console\\Question\\ChoiceQuestion::setMult
184
182
use Symfony\Component\Console\Question\ChoiceQuestion;
185
183
186
184
// ...
187
- public function execute (InputInterface $input, OutputInterface $output): int
185
+ public function __invoke (InputInterface $input, OutputInterface $output): int
188
186
{
189
187
// ...
190
- $helper = $this->getHelper('question' );
188
+ $helper = new QuestionHelper( );
191
189
$question = new ChoiceQuestion(
192
190
'Please select your favorite colors (defaults to red and blue)',
193
191
['red', 'blue', 'yellow'],
@@ -218,10 +216,10 @@ will be autocompleted as the user types::
218
216
use Symfony\Component\Console\Question\Question;
219
217
220
218
// ...
221
- public function execute (InputInterface $input, OutputInterface $output): int
219
+ public function __invoke (InputInterface $input, OutputInterface $output): int
222
220
{
223
221
// ...
224
- $helper = $this->getHelper('question' );
222
+ $helper = new QuestionHelper( );
225
223
226
224
$bundles = ['AcmeDemoBundle', 'AcmeBlogBundle', 'AcmeStoreBundle'];
227
225
$question = new Question('Please enter the name of a bundle', 'FooBundle');
@@ -241,9 +239,9 @@ provide a callback function to dynamically generate suggestions::
241
239
use Symfony\Component\Console\Question\Question;
242
240
243
241
// ...
244
- public function execute (InputInterface $input, OutputInterface $output): int
242
+ public function __invoke (InputInterface $input, OutputInterface $output): int
245
243
{
246
- $helper = $this->getHelper('question' );
244
+ $helper = new QuestionHelper( );
247
245
248
246
// This function is called whenever the input changes and new
249
247
// suggestions are needed.
@@ -282,10 +280,10 @@ You can also specify if you want to not trim the answer by setting it directly w
282
280
use Symfony\Component\Console\Question\Question;
283
281
284
282
// ...
285
- public function execute (InputInterface $input, OutputInterface $output): int
283
+ public function __invoke (InputInterface $input, OutputInterface $output): int
286
284
{
287
285
// ...
288
- $helper = $this->getHelper('question' );
286
+ $helper = new QuestionHelper( );
289
287
290
288
$question = new Question('What is the name of the child?');
291
289
$question->setTrimmable(false);
@@ -308,10 +306,10 @@ the response to a question should allow multiline answers by passing ``true`` to
308
306
use Symfony\Component\Console\Question\Question;
309
307
310
308
// ...
311
- public function execute (InputInterface $input, OutputInterface $output): int
309
+ public function __invoke (InputInterface $input, OutputInterface $output): int
312
310
{
313
311
// ...
314
- $helper = $this->getHelper('question' );
312
+ $helper = new QuestionHelper( );
315
313
316
314
$question = new Question('How do you solve world peace?');
317
315
$question->setMultiline(true);
@@ -335,10 +333,10 @@ convenient for passwords::
335
333
use Symfony\Component\Console\Question\Question;
336
334
337
335
// ...
338
- public function execute (InputInterface $input, OutputInterface $output): int
336
+ public function __invoke (InputInterface $input, OutputInterface $output): int
339
337
{
340
338
// ...
341
- $helper = $this->getHelper('question' );
339
+ $helper = new QuestionHelper( );
342
340
343
341
$question = new Question('What is the database password?');
344
342
$question->setHidden(true);
@@ -372,10 +370,10 @@ convenient for passwords::
372
370
use Symfony\Component\Console\Question\ChoiceQuestion;
373
371
374
372
// ...
375
- public function execute (InputInterface $input, OutputInterface $output): int
373
+ public function __invoke (InputInterface $input, OutputInterface $output): int
376
374
{
377
375
// ...
378
- $helper = $this->getHelper('question' );
376
+ $helper = new QuestionHelper( );
379
377
QuestionHelper::disableStty();
380
378
381
379
// ...
@@ -396,10 +394,10 @@ method::
396
394
use Symfony\Component\Console\Question\Question;
397
395
398
396
// ...
399
- public function execute (InputInterface $input, OutputInterface $output): int
397
+ public function __invoke (InputInterface $input, OutputInterface $output): int
400
398
{
401
399
// ...
402
- $helper = $this->getHelper('question' );
400
+ $helper = new QuestionHelper( );
403
401
404
402
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
405
403
$question->setNormalizer(function (string $value): string {
@@ -434,10 +432,10 @@ method::
434
432
use Symfony\Component\Console\Question\Question;
435
433
436
434
// ...
437
- public function execute (InputInterface $input, OutputInterface $output): int
435
+ public function __invoke (InputInterface $input, OutputInterface $output): int
438
436
{
439
437
// ...
440
- $helper = $this->getHelper('question' );
438
+ $helper = new QuestionHelper( );
441
439
442
440
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
443
441
$question->setValidator(function (string $answer): string {
@@ -494,10 +492,10 @@ You can also use a validator with a hidden question::
494
492
use Symfony\Component\Console\Question\Question;
495
493
496
494
// ...
497
- public function execute (InputInterface $input, OutputInterface $output): int
495
+ public function __invoke (InputInterface $input, OutputInterface $output): int
498
496
{
499
497
// ...
500
- $helper = $this->getHelper('question' );
498
+ $helper = new QuestionHelper( );
501
499
502
500
$question = new Question('Please enter your password');
503
501
$question->setNormalizer(function (?string $value): string {
0 commit comments