Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Debug formatter tweaks #4658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.