Skip to content

Commit 244cf19

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

File tree

6 files changed

+38
-45
lines changed

6 files changed

+38
-45
lines changed

components/console/helpers/debug_formatter.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ this:
1010
.. image:: /_images/components/console/debug_formatter.png
1111
:alt: Console output, with the first line showing "RUN Running figlet", followed by lines showing the output of the command prefixed with "OUT" and "RES Finished the command" as last line in the output.
1212

13-
Using the debug_formatter
13+
Using the Debug Formatter
1414
-------------------------
1515

16-
The formatter is included in the default helper set and you can get it by
17-
calling :method:`Symfony\\Component\\Console\\Command\\Command::getHelper`::
16+
The debug formatter helper can be instantiated directly as shown::
1817

19-
$debugFormatter = $this->getHelper('debug_formatter');
18+
$debugFormatter = new DebugFormatterHelper();
2019

21-
The formatter accepts strings and returns a formatted string, which you then
20+
It accepts strings and returns a formatted string, which you then
2221
output to the console (or even log the information or do anything else).
2322

2423
All methods of this helper have an identifier as the first argument. This is a

components/console/helpers/formatterhelper.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
Formatter Helper
22
================
33

4-
The Formatter helper provides functions to format the output with colors.
5-
You can do more advanced things with this helper than you can in
6-
:doc:`/console/coloring`.
4+
The :class:`Symfony\\Component\\Console\\Helper\\FormatterHelper` helper provides
5+
functions to format the output with colors. You can do more advanced things with
6+
this helper than you can in :doc:`/console/coloring`::
77

8-
The :class:`Symfony\\Component\\Console\\Helper\\FormatterHelper` is included
9-
in the default helper set and you can get it by calling
10-
:method:`Symfony\\Component\\Console\\Command\\Command::getHelper`::
11-
12-
$formatter = $this->getHelper('formatter');
8+
$formatter = new FormatterHelper();
139

1410
The methods return a string, which you'll usually render to the console by
1511
passing it to the

components/console/helpers/processhelper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ a very verbose verbosity (e.g. ``-vv``)::
1111

1212
use Symfony\Component\Process\Process;
1313

14-
$helper = $this->getHelper('process');
14+
$helper = new ProcessHelper();
1515
$process = new Process(['figlet', 'Symfony']);
1616

1717
$helper->run($output, $process);

components/console/helpers/questionhelper.rst

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ Question Helper
22
===============
33

44
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::
86

9-
$helper = $this->getHelper('question');
7+
$helper = new QuestionHelper();
108

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

2927
// ...
28+
use Symfony\Component\Console\Application;
3029
use Symfony\Component\Console\Attribute\AsCommand;
3130
use Symfony\Component\Console\Command\Command;
3231
use Symfony\Component\Console\Input\InputInterface;
@@ -38,7 +37,7 @@ the following to your command::
3837
{
3938
public function __invoke(InputInterface $input, OutputInterface $output): int
4039
{
41-
$helper = $this->getHelper('question');
40+
$helper = new QuestionHelper();
4241
$question = new ConfirmationQuestion('Continue with this action?', false);
4342

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

9392
// ...
94-
public function execute(InputInterface $input, OutputInterface $output): int
93+
public function __invoke(InputInterface $input, OutputInterface $output): int
9594
{
9695
// ...
9796
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
@@ -121,10 +120,10 @@ but ``red`` could be set instead (could be more explicit)::
121120
use Symfony\Component\Console\Question\ChoiceQuestion;
122121

123122
// ...
124-
public function execute(InputInterface $input, OutputInterface $output): int
123+
public function __invoke(InputInterface $input, OutputInterface $output): int
125124
{
126125
// ...
127-
$helper = $this->getHelper('question');
126+
$helper = new QuestionHelper();
128127
$question = new ChoiceQuestion(
129128
'Please select your favorite color (defaults to red)',
130129
// choices can also be PHP objects that implement __toString() method
@@ -184,10 +183,10 @@ this use :method:`Symfony\\Component\\Console\\Question\\ChoiceQuestion::setMult
184183
use Symfony\Component\Console\Question\ChoiceQuestion;
185184

186185
// ...
187-
public function execute(InputInterface $input, OutputInterface $output): int
186+
public function __invoke(InputInterface $input, OutputInterface $output): int
188187
{
189188
// ...
190-
$helper = $this->getHelper('question');
189+
$helper = new QuestionHelper();
191190
$question = new ChoiceQuestion(
192191
'Please select your favorite colors (defaults to red and blue)',
193192
['red', 'blue', 'yellow'],
@@ -218,10 +217,10 @@ will be autocompleted as the user types::
218217
use Symfony\Component\Console\Question\Question;
219218

220219
// ...
221-
public function execute(InputInterface $input, OutputInterface $output): int
220+
public function __invoke(InputInterface $input, OutputInterface $output): int
222221
{
223222
// ...
224-
$helper = $this->getHelper('question');
223+
$helper = new QuestionHelper();
225224

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

243242
// ...
244-
public function execute(InputInterface $input, OutputInterface $output): int
243+
public function __invoke(InputInterface $input, OutputInterface $output): int
245244
{
246-
$helper = $this->getHelper('question');
245+
$helper = new QuestionHelper();
247246

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

284283
// ...
285-
public function execute(InputInterface $input, OutputInterface $output): int
284+
public function __invoke(InputInterface $input, OutputInterface $output): int
286285
{
287286
// ...
288-
$helper = $this->getHelper('question');
287+
$helper = new QuestionHelper();
289288

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

310309
// ...
311-
public function execute(InputInterface $input, OutputInterface $output): int
310+
public function __invoke(InputInterface $input, OutputInterface $output): int
312311
{
313312
// ...
314-
$helper = $this->getHelper('question');
313+
$helper = new QuestionHelper();
315314

316315
$question = new Question('How do you solve world peace?');
317316
$question->setMultiline(true);
@@ -335,10 +334,10 @@ convenient for passwords::
335334
use Symfony\Component\Console\Question\Question;
336335

337336
// ...
338-
public function execute(InputInterface $input, OutputInterface $output): int
337+
public function __invoke(InputInterface $input, OutputInterface $output): int
339338
{
340339
// ...
341-
$helper = $this->getHelper('question');
340+
$helper = new QuestionHelper();
342341

343342
$question = new Question('What is the database password?');
344343
$question->setHidden(true);
@@ -372,10 +371,10 @@ convenient for passwords::
372371
use Symfony\Component\Console\Question\ChoiceQuestion;
373372

374373
// ...
375-
public function execute(InputInterface $input, OutputInterface $output): int
374+
public function __invoke(InputInterface $input, OutputInterface $output): int
376375
{
377376
// ...
378-
$helper = $this->getHelper('question');
377+
$helper = new QuestionHelper();
379378
QuestionHelper::disableStty();
380379

381380
// ...
@@ -396,10 +395,10 @@ method::
396395
use Symfony\Component\Console\Question\Question;
397396

398397
// ...
399-
public function execute(InputInterface $input, OutputInterface $output): int
398+
public function __invoke(InputInterface $input, OutputInterface $output): int
400399
{
401400
// ...
402-
$helper = $this->getHelper('question');
401+
$helper = new QuestionHelper();
403402

404403
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
405404
$question->setNormalizer(function (string $value): string {
@@ -434,10 +433,10 @@ method::
434433
use Symfony\Component\Console\Question\Question;
435434

436435
// ...
437-
public function execute(InputInterface $input, OutputInterface $output): int
436+
public function __invoke(InputInterface $input, OutputInterface $output): int
438437
{
439438
// ...
440-
$helper = $this->getHelper('question');
439+
$helper = new QuestionHelper();
441440

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

496495
// ...
497-
public function execute(InputInterface $input, OutputInterface $output): int
496+
public function __invoke(InputInterface $input, OutputInterface $output): int
498497
{
499498
// ...
500-
$helper = $this->getHelper('question');
499+
$helper = new QuestionHelper();
501500

502501
$question = new Question('Please enter your password');
503502
$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)