1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rawilk\LaravelModules\Commands\Generators; |
4
|
|
|
|
5
|
|
|
use Rawilk\LaravelModules\Support\Config\GenerateConfigReader; |
6
|
|
|
use Rawilk\LaravelModules\Support\Stub; |
7
|
|
|
use Rawilk\LaravelModules\Traits\ModuleCommands; |
8
|
|
|
|
9
|
|
|
class RuleMakeCommand extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
use ModuleCommands; |
12
|
|
|
|
13
|
|
|
/** @var string */ |
14
|
|
|
protected $argumentName = 'name'; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $signature = 'module:make-rule |
18
|
|
|
{name : The name of the rule class} |
19
|
|
|
{module? : The name of the module to create the rule for}'; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
protected $description = 'Create a new validation rule for the specified module.'; |
23
|
|
|
|
24
|
|
|
protected function getDefaultNamespace(): string |
25
|
|
|
{ |
26
|
|
|
/** @var \Rawilk\LaravelModules\Contracts\Repository $module */ |
27
|
|
|
$module = $this->laravel['modules']; |
28
|
|
|
|
29
|
|
|
return $module->config('paths.generator.rules.namespace') ?: $module->config('paths.generator.rules.path', 'Rules'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function getDestinationFilePath(): string |
33
|
|
|
{ |
34
|
|
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
35
|
|
|
|
36
|
|
|
$rulePath = GenerateConfigReader::read('rules'); |
37
|
|
|
|
38
|
|
|
return $path . $rulePath->getPath() . '/' . $this->getFileName() . '.php'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function getTemplateContents(): string |
42
|
|
|
{ |
43
|
|
|
/** @var \Rawilk\LaravelModules\Module $module */ |
44
|
|
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
45
|
|
|
|
46
|
|
|
return (new Stub('/rule.stub', [ |
47
|
|
|
'NAMESPACE' => $this->getClassNamespace($module), |
48
|
|
|
'CLASS' => $this->getClass(), |
49
|
|
|
]))->render(); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|