friendsofhyperf/closure-command

此包已被废弃且不再维护。作者建议使用 hyperf/command 包。

Hyperf 的 closure 命令组件。


README

Latest Stable Version Total Downloads License

Hyperf 的 closure 命令组件。

⚠️ 此组件已弃用,请使用 hyperf/command 代替。

安装

composer require friendsofhyperf/closure-command

发布

php bin/hyperf.php vendor:publish friendsofhyperf/closure-command

用法

  • 定义 ClosureCommand
// config/console.php

use FriendsOfHyperf\ClosureCommand\Console;
use FriendsOfHyperf\ClosureCommand\Inspiring;

Console::command('inspire', function () {
    $this->comment(Inspiring::quote());
})->describe('Display an inspiring quote');

Console::command('foo:bar', function() {
    $this->info('Command foo:bar executed.');
})->describe('Description of command foo::bar');
  • 定义 AnnotationCommand
<?php

namespace App\Service;

use FriendsOfHyperf\ClosureCommand\Annotation\Command;
use FriendsOfHyperf\ClosureCommand\Output;
use Hyperf\Di\Annotation\Inject;

#[Command(signature: 'foo:bar1', handle: 'bar1', description: 'The description of foo:bar1 command.')]
#[Command(signature: 'foo', description: 'The description of foo command.')]
class FooService
{
    use \Hyperf\Command\Concerns\InteractsWithIO;

    #[Command(signature: 'foo:bar {--bar=1 : Bar Value}', description: 'The description of foo:bar command.')]
    public function bar($bar)
    {
        $this->output?->info('Bar Value: ' . $bar);

        return $bar;
    }

    public function bar1()
    {
        $this->output?->info(__METHOD__);
    }

    public function handle()
    {
        $this->output?->info(__METHOD__);
    }
}

运行 php bin/hyperf.php

foo
  foo:bar                   The description of foo:bar command.
  foo:bar1                  The description of foo:bar1 command.

捐赠

如果您喜欢它们,请买我一杯咖啡。 支付宝 | 微信

联系

许可证

MIT