New in Symfony 7.2: Console Finished Indicator

Contributed by
Laurens Laman
in
#57576

The Symfony Console component has become the standard way of creating CLI
commands and applications in PHP. More than 11,000 open source projects use it,
and it’s close to 1 billion downloads since it was released in October 2011.

Rock-solid and mature components like this no longer add revolutionary new
features, but in each Symfony version, we improve it with small quality-of-life
and DX (developer experience) tweaks.

In Symfony 7.2, we improved the Console component to allow you to customize the
finished indicator. When using a progress indicator to let the user know
that the component is not stalled, by default, you see a rotating text spinner:

You can customize the progress indicator with your own spinner or animation.
The main issue is that when the command finishes, it displays the last progress
indicator used, which can vary each time you run the command. This inconsistency
in the final result is often less than ideal.

In Symfony 7.2 we’re improving this by showing ✔ as the finished indicator:

You can fully customize this value with the new finishedIndicatorValue option.
For example, you could show a different indicator based on the result of the command:

use SymfonyComponentConsoleHelperProgressIndicator;
// …

$progressIndicator = new ProgressIndicator($output, finishedIndicatorValue: ‚🎉‘);

try {
/* do some work here … */
$progressIndicator->finish(‚Finished‘);
} catch (Exception) {
$progressIndicator->finish(‚Failed‘, ‚🚨‘);
}

And this is how it looks when the command runs successfully:

Sponsor the Symfony project.

Symfony Blog

Read More

Latest News

PHP-Releases

PHP 8.4.1 released!

PHP 8.1.31 released!

PHP 8.3.14 released!

PHP 8.2.26 released!

Generated by Feedzy