10000 Applied comments from our great reviewers · symfony/symfony-docs@6a02f68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a02f68

Browse files
committed
Applied comments from our great reviewers
1 parent 363e38f commit 6a02f68

File tree

1 file changed

+30
-15
lines changed
  • components/console/helpers

1 file changed

+30
-15
lines changed

components/console/helpers/debug_formatter.rst

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
.. index::
22
single: Console Helpers; DebugFormatter Helper
33

4-
DebugFormatter Helper
5-
=====================
4+
Debug Formatter Helper
5+
======================
66

77
.. versionadded:: 2.6
8-
The DebugFormatter helper was introduced in Symfony 2.6.
8+
The Debug Formatter helper was introduced in Symfony 2.6.
99

1010
The :class:`Symfony\\Component\\Console\\Helper\\DebugFormatterHelper` provides
1111
functions to output debug information when running an external program, for
12-
instance a process or HTTP request. It is included in the default helper set,
13-
which you can get by calling
14-
:method:`Symfony\\Component\\Console\\Command\\Command::getHelperSet`::
12+
instance a process or HTTP request. It is included in the default helper set
13+
and you can get it by calling
14+
:method:`Symfony\\Component\\Console\\Command\\Command::getHelper`::
1515

1616
$debugFormatter = $this->getHelper('debug_formatter');
1717

1818
The formatter only formats strings, which you can use to output to the console,
19-
but also to log the information or anything else.
19+
but also to log the information or do anything else.
2020

21-
All methods of this helper have an identifier as the first argument. This is an
21+
All methods of this helper have an identifier as the first argument. This is a
2222
unique value for each program. This way, the helper can debug information for
2323
multiple programs at the same time. When using the
2424
:doc:`Process component </components/process>`, you probably want to use
2525
:phpfunction:`spl_object_hash`.
2626

2727
.. tip::
2828

29-
This information is often too verbose to show by default. You can use
29+
This information is often too verbose to be shown by default. You can use
3030
:ref:`verbosity levels <verbosity-levels>` to only show it when in
3131
debugging mode (``-vvv``).
3232

@@ -62,8 +62,17 @@ Some programs give output while they are running. This information can be shown
6262
using
6363
:method:`Symfony\\Component\\Console\\Helper\\DebugFormatterHelper::progress`::
6464

65+
use Symfony\Component\Process\Process;
66+
67+
// ...
68+
$process = new Process(...);
69+
70+
$process->run(function ($type, $buffer) use ($output, $debugFormatter, $process) {
71+
$output->writeln(
72+
$debugFormatter->progress(spl_object_hash($process), $buffer, Process::ERR === $type)
73+
);
74+
});
6575
// ...
66-
$output->writeln($debugFormatter->progress(spl_object_hash($process), $buffer, Process::ERR === $type));
6776

6877
In case of success, this will output:
6978

@@ -80,18 +89,24 @@ And this in case of failure:
8089
The third argument is a boolean which tells the function if the output is error
8190
output or not. When ``true``, the output is considered error output.
8291

83-
The fourth and fifth argument allow you to override the prefix for respectively
84-
the normal output and error output.
92+
The fourth and fifth argument allow you to override the prefix for the normal
93+
output and error output respectively.
8594

8695
Stopping a Program
8796
------------------
8897

8998
When a program is stopped, you can use
90-
:method:`Symfony\\Component\\Console\\Helper\\DebugFormatterHelper::progress`
91-
to notify this to the users::
99+
:method:`Symfony\\Component\\Console\\Helper\\DebugFormatterHelper::run` to
100+
notify this to the users::
92101

93102
// ...
94-
$output->writeln($debugFormatter->progress(spl_object_hash($process), 'Some command description', $process->isSuccesfull()));
103+
$output->writeln(
104+
$debugFormatter->stop(
105+
spl_object_hash($process),
106+
'Some command description',
107+
$process->isSuccessfull()
108+
)
109+
);
95110

96111
This will output:
97112

0 commit comments

Comments
 (0)
0