PHP code example of friendsofhyperf / closure-command
1. Go to this page and download the library: Download friendsofhyperf/closure-command library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
friendsofhyperf / closure-command example snippets
// 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');
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__);
}
}