Skip to content
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

[8.x] Add --implicit (and -i) option to make:rule #38480

Merged
merged 7 commits into from
Aug 23, 2021
Merged
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
30 changes: 30 additions & 0 deletions src/Illuminate/Foundation/Console/RuleMakeCommand.php
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
namespace Illuminate\Foundation\Console;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class RuleMakeCommand extends GeneratorCommand
{
@@ -27,6 +28,23 @@ class RuleMakeCommand extends GeneratorCommand
*/
protected $type = 'Rule';

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function buildClass($name)
{
return str_replace(
'{{ ruleType }}',
$this->option('implicit') ? 'ImplicitRule' : 'Rule',
parent::buildClass($name)
);
}

/**
* Get the stub file for the generator.
*
@@ -51,4 +69,16 @@ protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Rules';
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['implicit', 'i', InputOption::VALUE_NONE, 'Generate an implicit rule.'],
];
}
}
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Console/stubs/rule.stub
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@

namespace {{ namespace }};

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

class {{ class }} implements Rule
class {{ class }} implements {{ ruleType }}
{
/**
* Create a new rule instance.