Skip to content

Commit

Permalink
feature #4658 Debug formatter tweaks (weaverryan)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.6 branch.

Discussion
----------

Debug formatter tweaks

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | no
| Applies to    | 2.6+
| Fixed tickets | n/a

Hi guys!

This follows with a few tweaks to #4485. The biggest was adding an image of the output early on, which helped me understand "what the heck does this debug formatter actually do?".

Thanks!

Commits
-------

9e4eb5a language tweak thanks to xabbuh!
0f4fda7 Adding an example image of the debug_formatter
  • Loading branch information
weaverryan committed Jan 16, 2015
2 parents cfad26c + 9e4eb5a commit 08e5ac9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions components/console/helpers/debug_formatter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ Debug Formatter Helper

The :class:`Symfony\\Component\\Console\\Helper\\DebugFormatterHelper` provides
functions to output debug information when running an external program, for
instance a process or HTTP request. It is included in the default helper set
and you can get it by calling
:method:`Symfony\\Component\\Console\\Command\\Command::getHelper`::
instance a process or HTTP request. For example, if you used it to output
the results of running ``ls -la`` on a UNIX system, it might output something
like this:

.. image:: /images/components/console/debug_formatter.png
:align: center

Using the debug_formatter
-------------------------

The formatter is included in the default helper set and you can get it by
calling :method:`Symfony\\Component\\Console\\Command\\Command::getHelper`::

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

The formatter only formats strings, which you can use to output to the console,
but also to log the information or do anything else.
The formatter accepts strings and returns a formatted string, which you then
output to the console (or even log the information or do anything else).

All methods of this helper have an identifier as the first argument. This is a
unique value for each program. This way, the helper can debug information for
Expand All @@ -39,9 +48,13 @@ display information that the program is started::

// ...
$process = new Process(...);
$process->run();

$output->writeln($debugFormatter->start(spl_object_hash($process), 'Some process description'));
$output->writeln($debugFormatter->start(
spl_object_hash($process),
'Some process description')
);

$process->run();

This will output:

Expand All @@ -51,7 +64,11 @@ This will output:
You can tweak the prefix using the third argument::

$output->writeln($debugFormatter->start(spl_object_hash($process), 'Some process description', 'STARTED');
$output->writeln($debugFormatter->start(
spl_object_hash($process),
'Some process description',
'STARTED'
);
// will output:
// STARTED Some process description

Expand All @@ -69,7 +86,11 @@ using

$process->run(function ($type, $buffer) use ($output, $debugFormatter, $process) {
$output->writeln(
$debugFormatter->progress(spl_object_hash($process), $buffer, Process::ERR === $type)
$debugFormatter->progress(
spl_object_hash($process),
$buffer,
Process::ERR === $type
)
);
});
// ...
Expand Down
Binary file added images/components/console/debug_formatter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 08e5ac9

Please sign in to comment.