Skip to content

[10.x] Make invokable rules default #43868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.implicit.stub'
: '/stubs/rule.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.';
}
}