-
Notifications
You must be signed in to change notification settings - Fork 51
Progress Output
Bertie2011 edited this page Aug 29, 2021
·
1 revision
CLIFramework has built-in support for progress bars. Start by creating an instance from CLIFramework\ProgressBar
. You'll need an output stream, like the STDERR
or STDOUT
global constants and a CLIFramework\ServiceContainer
which you can get from the getService()
method on application. Inside a command you can use $this->getApplication()->getService()
.
Indicate the start of the process by calling setUnit($unit)
and start($title)
. Then indicate updates by optionally calling setTitle($title)
before updateLayout()
and update($finished, $total)
. End the process by calling finish($title)
.
See the example below:
$progress = new CLIFramework\Component\Progress\ProgressBar(STDOUT);
$progress->setUnit('bytes');
$progress->start('downloading file');
$total = 512;
for ($i = 0; $i <= $total; $i++) {
usleep(5 * 10000); //Simulate downloading file.
$progress->updateLayout();
$progress->update($i, $total);
}
$progress->finish();