friendsofhyperf/console-spinner

Custom progress bar component For Hyperf

0.1.1 2021-09-07 02:56 UTC

This package is auto-updated.

Last update: 2021-11-07 03:26:21 UTC


README

Open in Visual Studio Code Latest Stable Version Total Downloads GitHub license

Installation

composer require friendsofhyperf/console-spinner

Publish

  • Optional
php bin/hyperf.php vendor:publish friendsofhyperf/console-spinner

Usage

class FooCommand extends Command
{
    use Spinnerable;

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $spinner = $this->spinner($users->count());
        $spinner->setMessage('Loading...');
        $spinner->start();
        
        foreach ($users as $user) {
            // Do your stuff...
            
            $spinner->advance();
        }

        $spinner->finish();
    }
}

The $spinner is compatible with Symfony ProgressBar, so you can run any method of this class.

Or you can also use with withSpinner method by giving an iterable.

$this->withSpinner(User::all(), function($user) {
    // Do your stuff with $user
}, 'Loading...');