Last active
March 15, 2023 18:37
-
-
Save rodrigoslayertech/b12804d5a0c76adbf1c5272d8396618b to your computer and use it in GitHub Desktop.
Bootgly CLI vs Symfony Console - Progress Bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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