New in Symfony 2.3: Great new Features in the Console Component
May 8, 2013 • Published by Fabien Potencier
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Contributed by
Peter Kruithof
in #7300.
Progress helper enhancements
The console progress helper was added in 2.2. For 2.3, several enhancements were made to the display like avoiding too much flickering, or supporting UTF-8.
There is also one new feature, the possibility to set the current progress of the bar. That's interesting for instance when you are displaying the progress of a file download, where a callback provides the current download progress:
1 2 3 4 5
// advance the progress bar 1 unit
$progress->advance();
// set the progress bar manually
$progress->setCurrent(75);
Contributed by
Saša Stamenković
in #6368.
TableHelper
A lot of people were asking for a way to nicely display a table from the console. That's now possible in Symfony 2.3:
1 2 3 4 5 6 7 8 9 10 11
$table = $app->getHelperSet()->get('table');
$table
->setHeaders(array('ISBN', 'Title', 'Author'))
->setRows(array(
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens'),
array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'),
array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'),
))
;
$table->render($output);
And here is how it would be displayed:
I won't detail all the possible options as there is a nice cookbook entry for this feature.
Contributed by
Jean-François Simon
in #6368.
Console output in more Formats
Did you know that you can get the help for any given command in the XML format? It has been possible since symfony 1, and it is heavily used by many IDEs as a mean to wrap the Symfony CLI tool in a nice GUI.
As of Symfony 2.3, this feature has been abstracted so that you can now get the output in the Markdown, JSON, and XML format:
1 2 3
$ php app/console help some:command --format=json
$ php app/console list --format=json
Contributed by
Florin Patan and
Jordi Boggiano
in #7841.
More Verbosity Levels
Some commands gives you a more verbose output when using the --verbose
flag (or -v
). You can also remove all the output of a command by using the
--quiet
flag (or -q
).
As of 2.3, you now have access to three levels of verbosity:
1 2 3
$ php app/console foo --verbose=1 # equivalent to -v
$ php app/console foo --verbose=2 # equivalent to -vv
$ php app/console foo --verbose=3 # equivalent to -vvv
Composer already takes advantage of this feature. Upgrade to the latest
version of Composer, and try using -v
or -vv
when running composer
install
; you will see that Composer outputs interesting information that can
help you debug problems.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.