Name | Updated at | |
---|---|---|
.github | ||
src | ||
.gitattributes | ||
LICENSE | ||
README.md | ||
composer.json |
The command validation component for Hyperf.
composer require friendsofhyperf/command-validation
<?php
declare(strict_types=1);
namespace App\Command;
use FriendsOfHyperf\CommandValidation\Concerns\ValidatesInput;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
#[Command]
class FooCommand extends HyperfCommand
{
use ValidatesInput;
/**
* 执行的命令行
*/
protected string $name = 'foo:hello {?name : The name of the person to greet.}';
public function handle()
{
$this->info(sprintf('Hello %s.', $this->input->getArgument('name')));
}
public function rules(): array
{
return [
'name' => 'required',
];
}
protected function messages(): array
{
return [
'name.required' => 'The name is required.',
];
}
}
If you like them, Buy me a cup of coffee.
Alipay | Buy Me A Coffee | |
---|---|---|