@@ -9,14 +9,24 @@ Debug Formatter Helper
9
9
10
10
The :class: `Symfony\\ Component\\ Console\\ Helper\\ DebugFormatterHelper ` provides
11
11
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
- 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 `::
15
24
16
25
$debugFormatter = $this->getHelper('debug_formatter');
17
26
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).
20
30
21
31
All methods of this helper have an identifier as the first argument. This is a
22
32
unique value for each program. This way, the helper can debug information for
@@ -39,9 +49,13 @@ display information that the program is started::
39
49
40
50
// ...
41
51
$process = new Process(...);
42
- $process->run();
43
52
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();
45
59
46
60
This will output:
47
61
@@ -51,7 +65,11 @@ This will output:
51
65
52
66
You can tweak the prefix using the third argument::
53
67
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
+ );
55
73
// will output:
56
74
// STARTED Some process description
57
75
69
87
70
88
$process->run(function ($type, $buffer) use ($output, $debugFormatter, $process) {
71
89
$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
+ )
73
95
);
74
96
});
75
97
// ...
0 commit comments