Skip to content

Instantly share code, notes, and snippets.

@rodrigoslayertech
Last active March 15, 2023 18:37
Show Gist options
  • Save rodrigoslayertech/b12804d5a0c76adbf1c5272d8396618b to your computer and use it in GitHub Desktop.
Save rodrigoslayertech/b12804d5a0c76adbf1c5272d8396618b to your computer and use it in GitHub Desktop.
Bootgly CLI vs Symfony Console - Progress Bar
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;
$output = new ConsoleOutput();
// creates a new progress bar (50 units)
$progressBar = new ProgressBar($output, 250000, 0);
$progressBar->setFormat(<<<'TEMPLATE'
%message%
%current%/%max% [%bar%] %percent%%
⏱️ %elapsed% / 🏁 %remaining%
TEMPLATE);
$progressBar->setRedrawFrequency(1);
$progressBar->minSecondsBetweenRedraws(0);
$progressBar->setBarWidth(10);
// Bar symbols
$progressBar->setBarCharacter('❤️');
$progressBar->setEmptyBarCharacter('🖤');
$progressBar->setProgressCharacter('');
// starts and displays the progress bar
$progressBar->start();
$i = 0;
while ($i++ < 250000) {
if ($i === 1) {
$progressBar->setMessage('Performing progress!');
}
if ($i === 125000) {
$progressBar->setMessage('There\'s only half left...');
}
if ($i === 249999) {
$progressBar->setMessage('Finished!!!');
}
$progressBar->advance();
}
// ensures that the progress bar is at 100%
$progressBar->finish();
// Source code of Bootgly:
// https://gist.github.com/rodrigoslayertech/5129f053a778e3b9b495fb2fceee94bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment