friendsofhyperf/console-spinner

Hyperf 的进度条组件。


README

Latest Stable Version Total Downloads License

Hyperf 的进度条组件。

安装

composer require friendsofhyperf/console-spinner

发布

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

用法

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();
    }
}

$spinner 与 Symfony ProgressBar 兼容,因此您可以使用此类中的任何方法。

或者,您也可以通过给一个可迭代的给 withSpinner 方法使用。

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

联系

许可证

MIT