Skip to content

Commit

Permalink
make invokable rules default
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Aug 26, 2022
1 parent 32b1336 commit 07c98d1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 56 deletions.
13 changes: 3 additions & 10 deletions src/Illuminate/Foundation/Console/RuleMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,9 @@ protected function buildClass($name)
*/
protected function getStub()
{
$stub = '/stubs/rule.stub';

if ($this->option('invokable')) {
$stub = '/stubs/rule.invokable.stub';
}

if ($this->option('implicit') && $this->option('invokable')) {
$stub = str_replace('.stub', '.implicit.stub', $stub);
}
$stub = $this->option('implicit')
? '/stubs/rule.stub'
: '/stubs/rule.implicit.stub';

return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
? $customPath
Expand All @@ -89,7 +83,6 @@ protected function getOptions()
{
return [
['implicit', 'i', InputOption::VALUE_NONE, 'Generate an implicit rule.'],
['invokable', null, InputOption::VALUE_NONE, 'Generate a single method, invokable rule class.'],
];
}
}
21 changes: 0 additions & 21 deletions src/Illuminate/Foundation/Console/stubs/rule.invokable.stub

This file was deleted.

31 changes: 6 additions & 25 deletions src/Illuminate/Foundation/Console/stubs/rule.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,20 @@

namespace {{ namespace }};

use Illuminate\Contracts\Validation\{{ ruleType }};
use Illuminate\Contracts\Validation\InvokableRule;

class {{ class }} implements {{ ruleType }}
class {{ class }} implements InvokableRule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Determine if the validation rule passes.
* Run the validation rule.
*
* @param string $attribute
* @param mixed $value
* @return bool
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function passes($attribute, $value)
public function __invoke($attribute, $value, $fail)
{
//
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The validation error message.';
}
}

0 comments on commit 07c98d1

Please sign in to comment.