0
7
Login
Code
Issues
Pull requests
Events
Packages
21e29ca758fc420bd7179e9a122e01330fda5a73
21e29ca758fc420bd7179e9a122e01330fda5a73

closure-command

Latest Stable Version Total Downloads License

Installation

composer require friendsofhyperf/closure-command

Publish

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

Usage

  • Define ClosureCommand
// config/console.php

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

use function FriendsOfHyperf\ClosureCommand\command;

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');

command('whoami', function () {
    $this->info('Your are friend of hyperf');
})->describe('Who am I');
  • Define AnnotationCommand
use FriendsOfHyperf\ClosureCommand\Annotation\Command;
use Hyperf\Contract\StdoutLoggerInterface;
use FriendsOfHyperf\ClosureCommand\Input;
use FriendsOfHyperf\ClosureCommand\Output;

class Foo
{
    #[Command(signature: 'foo:bar {--bar=1}', description: 'Test foo::bar')]
    public function bar($bar, Input $input, Output $output)
    {
        $output->info('$bar:' . $bar);
        $output->warning('foo::bar executed.');
    }
}