1. 云栖社区>
  2. PHP教程>
  3. 正文

New in Symfony 2.8: Console improvements

作者:用户 来源:互联网 时间:2017-12-01 18:45:37

New in Symfony 2.8: Console improvements - 摘要: 本文讲的是New in Symfony 2.8: Console improvements, The Symfony Console component is our second most popular component, with more than 1 million monthly downloads and mor

The Symfony Console component is our second most popular component, with more than 1 million monthly downloads and more than 2,300 projects depending on it. In Symfony 2.8 we extended its capabilities with some new features.

Allowed to apply styles to table columns¶

Contributed by

Max Grigorian in #14044 .

Symfony 2.8 allows to define a different visual style for each table column. First, instantiate the TableStyle class to define the style features:

use Symfony/Component/Console/Helper/TableStyle;$leftAligned = new TableStyle();$leftAligned->setPadType(STR_PAD_LEFT);

Then, apply the custom style to any table column through its column numeric index:

use Symfony/Component/Console/Helper/Table;$table = new Table($output);$table->setHeaders(['#', 'Path', 'Size']);$table->setColumnStyle(2, $leftAligned);// ...$table->render();

Now, when rendering the table, the contents of the third column (numeric index = 2 ) will be left aligned:

+---+---------------------+---------+| # | Path | Size |+---+---------------------+---------+| 1 | autoload.php | 183 || 2 | ApplicationTest.php | 247,794 || 3 | CommandTest.php | 14,965 || 4 | ListCommandTest.php | 2,369 |+---+---------------------+---------+ Made exceptions visible in quiet mode¶ New in Symfony 2.8: Console improvements

Contributed by

Jordi Boggiano in #15772 .

In some environments it's common to run console commands with the --quiet option to avoid displaying any output. The problem is that this quiet mode also suppress the output when an exception occurs.

In Symfony 2.8, the behavior of the "quiet verbosity mode" has changed to always display the exception details when such an error occurs. This will make your life as a developer easier and it aligns with our Developer Experience commitment .

Added a progress indicator helper¶ New in Symfony 2.8: Console improvements

Contributed by

Kevin Bond in #16409 .

Theprogress bar helper allows to create cool animated indicators of the progress of some task. They are useful when you know beforehand when the task will finish, as in the Symfony Installer download progress bar.

However, it's common to execute tasks where you can't determine in advance when they'll be completed. That's why we've added a new progress indicator helper which displays a spinning bar while the task is running:

New in Symfony 2.8: Console improvements

In addition to the spinning bar, you can output messages while the progress indicator is still active:

use Symfony/Component/Console/Helper/ProgressIndicator;$progress = new ProgressIndicator($output);$progress->start('Starting...');// do something ...$progress->advance();// do something ...$progress->setMessage('Just started...');// do something ...$progress->setMessage('Half way...');// do something ...$progress->setMessage('Almost Done...');// do something ...$progress->finish('Done.');

Another nice feature of this progress indicator is that it gracefully degrades when the system doesn't support ANSI codes:

New in Symfony 2.8: Console improvements

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索,以便于您获取更多的相关知识。