Skip to content

Commit 3986174

Browse files
committed
Wouter's Review (WIP)
1 parent 1a9a5d7 commit 3986174

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

components/console/helpers/questionhelper.rst

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ Question Helper
44
The :class:`Symfony\\Component\\Console\\Helper\\QuestionHelper` provides
55
functions to ask the user for more information. It is included in the default
66
helper set and you can get it by calling
7-
:method:`Symfony\\Component\\Console\\Command\\Command::getHelper`::
7+
:method:`Symfony\\Component\\Console\\Application::getHelperSet`::
88

9-
$helper = $this->getHelper('question');
9+
use Symfony\Component\Console\Application;
10+
11+
public function __invoke(Application $application): int
12+
{
13+
$helper = $application->getHelperSet()->get('question');
14+
15+
// ...
16+
}
1017

1118
The Question Helper has a single method
1219
:method:`Symfony\\Component\\Console\\Helper\\QuestionHelper::ask` that needs an
@@ -27,6 +34,7 @@ Suppose you want to confirm an action before actually executing it. Add
2734
the following to your command::
2835

2936
// ...
37+
use Symfony\Component\Console\Application;
3038
use Symfony\Component\Console\Attribute\AsCommand;
3139
use Symfony\Component\Console\Command\Command;
3240
use Symfony\Component\Console\Input\InputInterface;
@@ -36,9 +44,9 @@ the following to your command::
3644
#[AsCommand(name: 'app:my-command')]
3745
class MyCommand
3846
{
39-
public function __invoke(InputInterface $input, OutputInterface $output): int
47+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
4048
{
41-
$helper = $this->getHelper('question');
49+
$helper = $application->getHelperSet()->get('question');
4250
$question = new ConfirmationQuestion('Continue with this action?', false);
4351

4452
if (!$helper->ask($input, $output, $question)) {
@@ -91,7 +99,7 @@ if you want to know a bundle name, you can add this to your command::
9199
use Symfony\Component\Console\Question\Question;
92100

93101
// ...
94-
public function execute(InputInterface $input, OutputInterface $output): int
102+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
95103
{
96104
// ...
97105
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
@@ -121,10 +129,10 @@ but ``red`` could be set instead (could be more explicit)::
121129
use Symfony\Component\Console\Question\ChoiceQuestion;
122130

123131
// ...
124-
public function execute(InputInterface $input, OutputInterface $output): int
132+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
125133
{
126134
// ...
127-
$helper = $this->getHelper('question');
135+
$helper = $application->getHelperSet()->get('question');
128136
$question = new ChoiceQuestion(
129137
'Please select your favorite color (defaults to red)',
130138
// choices can also be PHP objects that implement __toString() method
@@ -184,10 +192,10 @@ this use :method:`Symfony\\Component\\Console\\Question\\ChoiceQuestion::setMult
184192
use Symfony\Component\Console\Question\ChoiceQuestion;
185193

186194
// ...
187-
public function execute(InputInterface $input, OutputInterface $output): int
195+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
188196
{
189197
// ...
190-
$helper = $this->getHelper('question');
198+
$helper = $application->getHelperSet()->get('question');
191199
$question = new ChoiceQuestion(
192200
'Please select your favorite colors (defaults to red and blue)',
193201
['red', 'blue', 'yellow'],
@@ -218,10 +226,10 @@ will be autocompleted as the user types::
218226
use Symfony\Component\Console\Question\Question;
219227

220228
// ...
221-
public function execute(InputInterface $input, OutputInterface $output): int
229+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
222230
{
223231
// ...
224-
$helper = $this->getHelper('question');
232+
$helper = $application->getHelperSet()->get('question');
225233

226234
$bundles = ['AcmeDemoBundle', 'AcmeBlogBundle', 'AcmeStoreBundle'];
227235
$question = new Question('Please enter the name of a bundle', 'FooBundle');
@@ -241,9 +249,9 @@ provide a callback function to dynamically generate suggestions::
241249
use Symfony\Component\Console\Question\Question;
242250

243251
// ...
244-
public function execute(InputInterface $input, OutputInterface $output): int
252+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
245253
{
246-
$helper = $this->getHelper('question');
254+
$helper = $application->getHelperSet()->get('question');
247255

248256
// This function is called whenever the input changes and new
249257
// suggestions are needed.
@@ -282,10 +290,10 @@ You can also specify if you want to not trim the answer by setting it directly w
282290
use Symfony\Component\Console\Question\Question;
283291

284292
// ...
285-
public function execute(InputInterface $input, OutputInterface $output): int
293+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
286294
{
287295
// ...
288-
$helper = $this->getHelper('question');
296+
$helper = $application->getHelperSet()->get('question');
289297

290298
$question = new Question('What is the name of the child?');
291299
$question->setTrimmable(false);
@@ -308,10 +316,10 @@ the response to a question should allow multiline answers by passing ``true`` to
308316
use Symfony\Component\Console\Question\Question;
309317

310318
// ...
311-
public function execute(InputInterface $input, OutputInterface $output): int
319+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
312320
{
313321
// ...
314-
$helper = $this->getHelper('question');
322+
$helper = $application->getHelperSet()->get('question');
315323

316324
$question = new Question('How do you solve world peace?');
317325
$question->setMultiline(true);
@@ -335,10 +343,10 @@ convenient for passwords::
335343
use Symfony\Component\Console\Question\Question;
336344

337345
// ...
338-
public function execute(InputInterface $input, OutputInterface $output): int
346+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
339347
{
340348
// ...
341-
$helper = $this->getHelper('question');
349+
$helper = $application->getHelperSet()->get('question');
342350

343351
$question = new Question('What is the database password?');
344352
$question->setHidden(true);
@@ -372,10 +380,10 @@ convenient for passwords::
372380
use Symfony\Component\Console\Question\ChoiceQuestion;
373381

374382
// ...
375-
public function execute(InputInterface $input, OutputInterface $output): int
383+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
376384
{
377385
// ...
378-
$helper = $this->getHelper('question');
386+
$helper = $application->getHelperSet()->get('question');
379387
QuestionHelper::disableStty();
380388

381389
// ...
@@ -396,10 +404,10 @@ method::
396404
use Symfony\Component\Console\Question\Question;
397405

398406
// ...
399-
public function execute(InputInterface $input, OutputInterface $output): int
407+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
400408
{
401409
// ...
402-
$helper = $this->getHelper('question');
410+
$helper = $application->getHelperSet()->get('question');
403411

404412
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
405413
$question->setNormalizer(function (string $value): string {
@@ -434,10 +442,10 @@ method::
434442
use Symfony\Component\Console\Question\Question;
435443

436444
// ...
437-
public function execute(InputInterface $input, OutputInterface $output): int
445+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
438446
{
439447
// ...
440-
$helper = $this->getHelper('question');
448+
$helper = $application->getHelperSet()->get('question');
441449

442450
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
443451
$question->setValidator(function (string $answer): string {
@@ -494,10 +502,10 @@ You can also use a validator with a hidden question::
494502
use Symfony\Component\Console\Question\Question;
495503

496504
// ...
497-
public function execute(InputInterface $input, OutputInterface $output): int
505+
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
498506
{
499507
// ...
500-
$helper = $this->getHelper('question');
508+
$helper = $application->getHelperSet()->get('question');
501509

502510
$question = new Question('Please enter your password');
503511
$question->setNormalizer(function (?string $value): string {

console/calling_commands.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ arguments and options you want to pass to the command. The command name must be
1414
the first argument.
1515

1616
Eventually, calling the ``doRun()`` method actually runs the command and returns
17-
the returned code from the command (return value from command ``execute()``
17+
the returned code from the command (return value from command ``__invoke()``
1818
method)::
1919

2020
// ...
2121
use Symfony\Component\Console\Attribute\AsCommand;
22-
use Symfony\Component\Console\Command;
2322
use Symfony\Component\Console\Input\ArrayInput;
2423
use Symfony\Component\Console\Output\OutputInterface;
2524

console/style.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ which allow to create *semantic* commands and forget about their styling.
4242
Basic Usage
4343
-----------
4444

45-
In your `__invoke` method, add an argument of type :class:`Symfony\\Component\\Console\\Style\\SymfonyStyle`.
45+
In your ``__invoke()`` method, add an argument of type :class:`Symfony\\Component\\Console\\Style\\SymfonyStyle`.
4646
Then, you can start using any of its helpers, such as ``title()``, which
4747
displays the title of the command::
4848

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy