Skip to content

Commit 20137ae

Browse files
[8.x] Add --implicit (and -i) option to make:rule (#38480)
* Add $baseRule to stub * {{ ruleType }} instead of {{ $baseRule }} * Use --implicit option to switch to ImplicitRule * Add getOptions method * Add missing import * Deference to our StyleCI overlord * Update RuleMakeCommand.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent b5300a1 commit 20137ae

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/Illuminate/Foundation/Console/RuleMakeCommand.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Foundation\Console;
44

55
use Illuminate\Console\GeneratorCommand;
6+
use Symfony\Component\Console\Input\InputOption;
67

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

31+
/**
32+
* Build the class with the given name.
33+
*
34+
* @param string $name
35+
* @return string
36+
*
37+
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
38+
*/
39+
protected function buildClass($name)
40+
{
41+
return str_replace(
42+
'{{ ruleType }}',
43+
$this->option('implicit') ? 'ImplicitRule' : 'Rule',
44+
parent::buildClass($name)
45+
);
46+
}
47+
3048
/**
3149
* Get the stub file for the generator.
3250
*
@@ -51,4 +69,16 @@ protected function getDefaultNamespace($rootNamespace)
5169
{
5270
return $rootNamespace.'\Rules';
5371
}
72+
73+
/**
74+
* Get the console command options.
75+
*
76+
* @return array
77+
*/
78+
protected function getOptions()
79+
{
80+
return [
81+
['implicit', 'i', InputOption::VALUE_NONE, 'Generate an implicit rule.'],
82+
];
83+
}
5484
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace {{ namespace }};
44

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

7-
class {{ class }} implements Rule
7+
class {{ class }} implements {{ ruleType }}
88
{
99
/**
1010
* Create a new rule instance.

0 commit comments

Comments
 (0)