Archives


Master Symfony2 fundamentals

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Discover the SensioLabs Support

Access to the SensioLabs Competency Center for an exclusive and tailor-made support on Symfony
sensiolabs.com

Fabien Potencier
New in Symfony 2.3: Great new Features in the Console Component
by Fabien Potencier – May 08, 2013 – 9 comments

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:

Table in the CLI

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.

Comments RSS

  • KonstantinKuklin
    #1 KonstantinKuklin said on the 2013/05/08 at 18:25
    like magic
  • Romain Gautier
    #2 Romain Gautier said on the 2013/05/08 at 18:54
    Great work!
  • Loïc Chardonnet
    #3 Loïc Chardonnet said on the 2013/05/08 at 22:45
    Brilliant!
  • Nick Winfield
    #4 Nick Winfield said on the 2013/05/08 at 23:25
    Thumbs up!
  • Pablo Godel
    #5 Pablo Godel said on the 2013/05/09 at 14:44
    It keeps getting better and better, so awesome!
  • Roman Piekarski
    #6 Roman Piekarski said on the 2013/05/09 at 18:26
    Good features. Console component is really powerful and useful. Nice to see few new improvements. Good job guys.
  • Patrik Karisch
    #7 Patrik Karisch said on the 2013/05/09 at 21:04
    charming
  • Mehdi Mays
    #8 Mehdi Mays said on the 2013/05/10 at 06:49
    Great job thank you !!!
  • Hugo Hamon
    #9 Hugo Hamon said on the 2013/05/11 at 15:08
    The table output helper looks brilliant!