Skip to content

Commit d6d92eb

Browse files
authored
make invokable rules default (#43868)
1 parent 32b1336 commit d6d92eb

File tree

4 files changed

+9
-56
lines changed

4 files changed

+9
-56
lines changed

src/Illuminate/Foundation/Console/RuleMakeCommand.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,9 @@ protected function buildClass($name)
5454
*/
5555
protected function getStub()
5656
{
57-
$stub = '/stubs/rule.stub';
58-
59-
if ($this->option('invokable')) {
60-
$stub = '/stubs/rule.invokable.stub';
61-
}
62-
63-
if ($this->option('implicit') && $this->option('invokable')) {
64-
$stub = str_replace('.stub', '.implicit.stub', $stub);
65-
}
57+
$stub = $this->option('implicit')
58+
? '/stubs/rule.implicit.stub'
59+
: '/stubs/rule.stub';
6660

6761
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
6862
? $customPath
@@ -89,7 +83,6 @@ protected function getOptions()
8983
{
9084
return [
9185
['implicit', 'i', InputOption::VALUE_NONE, 'Generate an implicit rule.'],
92-
['invokable', null, InputOption::VALUE_NONE, 'Generate a single method, invokable rule class.'],
9386
];
9487
}
9588
}

src/Illuminate/Foundation/Console/stubs/rule.invokable.stub

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Illuminate/Foundation/Console/stubs/rule.stub

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,20 @@
22

33
namespace {{ namespace }};
44

5-
use Illuminate\Contracts\Validation\{{ ruleType }};
5+
use Illuminate\Contracts\Validation\InvokableRule;
66

7-
class {{ class }} implements {{ ruleType }}
7+
class {{ class }} implements InvokableRule
88
{
99
/**
10-
* Create a new rule instance.
11-
*
12-
* @return void
13-
*/
14-
public function __construct()
15-
{
16-
//
17-
}
18-
19-
/**
20-
* Determine if the validation rule passes.
10+
* Run the validation rule.
2111
*
2212
* @param string $attribute
2313
* @param mixed $value
24-
* @return bool
14+
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
15+
* @return void
2516
*/
26-
public function passes($attribute, $value)
17+
public function __invoke($attribute, $value, $fail)
2718
{
2819
//
2920
}
30-
31-
/**
32-
* Get the validation error message.
33-
*
34-
* @return string
35-
*/
36-
public function message()
37-
{
38-
return 'The validation error message.';
39-
}
4021
}

0 commit comments

Comments
 (0)