Last active
May 28, 2019 16:10
-
-
Save jeffochoa/1113e86a6ceaf61c914f2a4f0def630e to your computer and use it in GitHub Desktop.
ProgressBar callback trait for Laravel commands
This file contains 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
<?php | |
$users = App\User::all(); | |
$bar = $this->output->createProgressBar(count($users)); | |
$bar->start(); | |
foreach ($users as $user) { | |
$this->performTask($user); | |
$bar->advance(); | |
} | |
$bar->finish(); | |
This file contains 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
<?php | |
namespace App\commands; | |
trait ProgressionBarOutput | |
{ | |
public function runProcess(\Countable $countable, callable $callback) | |
{ | |
$bar = $this->output->createProgressBar(count($countable)); | |
$bar->start(); | |
foreach ($countable as $item) { | |
call_user_func($callback, $item); | |
$bar->advance(); | |
} | |
$bar->finish(); | |
$this->line(''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment