Skip to content

lajosbencz/php-progress-bar

Repository files navigation

php-progress-bar

Build Status Code Coverage

Extensible ANSI (only for terminals) progress bar for PHP

Install

composer require --save lajosbencz/progress-bar

Default usage

use LajosBencz\ProgressBar;

$pb = ProgressBar\Factory::createDefault(10);

for($i=0; $i<10; $i++) {
    sleep(1);
    $pb($i + 1);
}

Customized usage

use LajosBencz\ProgressBar;

$pb = new ProgressBar\ProgressBar(10);
$pb->setFormatterClass(ProgressBar\Formatter\SimpleFormatter::class, [60]);
$pb->setOutput(STDOUT);

for($i=0; $i<10; $i++) {
    sleep(1);
    $pb($i + 1);
}

Factory usage

use LajosBencz\ProgressBar;

$pbf = new ProgressBar\Factory(
    // formatter class name:
    ProgressBar\Formatter\SimpleFormatter::class,
    // formatter args, will be passed into the constructor:
    [10, "|O-|"],
    // output stream to write to:
    STDERR
);

$pb = $pbf->create(10);
for($i=0; $i<10; $i++) {
    sleep(1);
    $pb($i + 1);
}

TODO

  • Comments
  • Interface with PSR logging facility
  • Meaningful tests