@@ -9,14 +9,24 @@ Debug Formatter Helper
99
1010The :class: `Symfony\\ Component\\ Console\\ Helper\\ DebugFormatterHelper ` provides
1111functions 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- and you can get it by calling
14- :method: `Symfony\\ Component\\ Console\\ Command\\ Command::getHelper `::
12+ instance a process or HTTP request. For example, if you used it to output
13+ the results of running ``ls -la `` on a UNIX system, it might output something
14+ like this:
15+
16+ .. image :: /images/components/console/debug_formatter.png
17+ :align: center
18+
19+ Using the debug_formatter
20+ -------------------------
21+
22+ The formatter is included in the default helper set and you can get it by
23+ calling :method: `Symfony\\ Component\\ Console\\ Command\\ Command::getHelper `::
1524
1625 $debugFormatter = $this->getHelper('debug_formatter');
1726
18- The formatter only formats strings, which you can use to output to the console,
19- but also to log the information or do anything else.
27+ The formatter accepts strings and returns a formatted string, which you can
28+ use to output to the console (or you could even log the information or do
29+ something else).
2030
2131All methods of this helper have an identifier as the first argument. This is a
2232unique value for each program. This way, the helper can debug information for
@@ -39,9 +49,13 @@ display information that the program is started::
3949
4050 // ...
4151 $process = new Process(...);
42- $process->run();
4352
44- $output->writeln($debugFormatter->start(spl_object_hash($process), 'Some process description'));
53+ $output->writeln($debugFormatter->start(
54+ spl_object_hash($process),
55+ 'Some process description')
56+ );
57+
58+ $process->run();
4559
4660This will output:
4761
@@ -51,7 +65,11 @@ This will output:
5165
5266 You can tweak the prefix using the third argument::
5367
54- $output->writeln($debugFormatter->start(spl_object_hash($process), 'Some process description', 'STARTED');
68+ $output->writeln($debugFormatter->start(
69+ spl_object_hash($process),
70+ 'Some process description',
71+ 'STARTED'
72+ );
5573 // will output:
5674 // STARTED Some process description
5775
6987
7088 $process->run(function ($type, $buffer) use ($output, $debugFormatter, $process) {
7189 $output->writeln(
72- $debugFormatter->progress(spl_object_hash($process), $buffer, Process::ERR === $type)
90+ $debugFormatter->progress(
91+ spl_object_hash($process),
92+ $buffer,
93+ Process::ERR === $type
94+ )
7395 );
7496 });
7597 // ...
0 commit comments