friendsofhyperf / command-validation
The command validation component for Hyperf.
Fund package maintenance!
huangdijia
hdj.me/sponsors
Requires
- hyperf/command: ~3.1.13
- hyperf/context: ~3.1.0
- hyperf/di: ~3.1.0
- hyperf/stringable: ~3.1.0
- hyperf/support: ~3.1.0
- hyperf/validation: ~3.1.0
This package is auto-updated.
Last update: 2024-12-04 02:41:27 UTC
README
The command validation component for Hyperf.
Installation
composer require friendsofhyperf/command-validation
Usage
<?php declare(strict_types=1); namespace App\Command; use FriendsOfHyperf\CommandValidation\Traits\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'))); } protected function rules(): array { return [ 'name' => 'required', ]; } protected function messages(): array { return [ 'name.required' => 'The name is required.', ]; } }