devlop / laravel-console-input-validation
一个简化Laravel命令行中控制台输入验证的特质
1.1.2
2024-01-12 07:41 UTC
Requires
- php: ^7.4|^8.0
- illuminate/console: ^8.0|^9.0|^10.0|^11.0
- psr/log: ^1.0.1
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^5.2
README
Laravel Console Input Validation
一个小特质,使验证Laravel命令的输入变得更加容易。
安装
composer require devlop/laravel-console-input-validation
用法
use Devlop\Laravel\Console\ValidateInput; use Symfony\Component\Console\Input\InputInterface; class DemoCommand extends Command { use ValidateInput; /** * Validate the console command input. * * @throws InvalidArgumentException */ protected function validate(InputInterface $input) : void { // Example using manual validation if (! is_numeric($input->getOption('limit'))) { throw new InvalidArgumentException('--limit must be numeric'); } // Example using webmozarts/assert Assert::numeric($input->getOption('limit')); // assert that the --limit option got a numeric value Assert::greaterThan($input->getOption('limit'), 0); // assert that the --limit option get a value greater than 0 } public function handle() : int { // ... } }