File tree 1 file changed +2
-9
lines changed
1 file changed +2
-9
lines changed Original file line number Diff line number Diff line change @@ -17,19 +17,12 @@ composer require devlop/laravel-console-input-validation
17
17
18
18
``` php
19
19
use Devlop\Laravel\Console\ValidateInput;
20
- use InvalidArgumentException;
21
20
use Symfony\Component\Console\Input\InputInterface;
22
- use Webmozart\Assert\Assert; // not required, but used in the example below
23
21
24
22
class DemoCommand extends Command
25
23
{
26
24
use ValidateInput;
27
25
28
- public function __construct()
29
- {
30
- parent::__construct();
31
- }
32
-
33
26
/**
34
27
* Validate the console command input.
35
28
*
@@ -39,10 +32,10 @@ class DemoCommand extends Command
39
32
{
40
33
// Example using manual validation
41
34
if (! is_numeric($input->getOption('limit'))) {
42
- throw new RuntimeException ('--limit must be numeric');
35
+ throw new InvalidArgumentException ('--limit must be numeric');
43
36
}
44
37
45
- // Example using webmozarts/assert:
38
+ // Example using webmozarts/assert
46
39
Assert::numeric($input->getOption('limit')); // assert that the --limit option got a numeric value
47
40
Assert::greaterThan($input->getOption('limit'), 0); // assert that the --limit option get a value greater than 0
48
41
}
You can’t perform that action at this time.
0 commit comments