1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelModulize\Console\Commands; |
4
|
|
|
|
5
|
|
|
use LaravelModulize\Contracts\ModulizerRepositoryInterface; |
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
7
|
|
|
|
8
|
|
|
class GenerateFactoryCommand extends BaseGeneratorCommand |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The name and signature of the console command. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $signature = 'modulize:make:factory {module} {name} {model?}'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The console command description. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $description = 'Command to generate a model factory'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get the stub file for the generator. |
26
|
|
|
* |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
protected function getStub(): string |
30
|
|
|
{ |
31
|
|
|
return __DIR__ . '/stubs/Factory.stub'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get the destination class path. |
36
|
|
|
* |
37
|
|
|
* @param string $name |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
protected function getPath($name): string |
41
|
|
|
{ |
42
|
|
|
$name = str_replace( |
43
|
|
|
['\\', '/'], '', $this->argument('name') |
44
|
|
|
); |
45
|
|
|
return $this->repository->databasePath($this->module) . "/factories/{$name}.php"; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Build the class with the given name. |
50
|
|
|
* |
51
|
|
|
* @param string $name |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
protected function buildClass($name) |
55
|
|
|
{ |
56
|
|
|
$model = $this->argument('model') ?? 'Model'; |
57
|
|
|
|
58
|
|
|
return str_replace( |
59
|
|
|
'DummyModel', $model, parent::buildClass($name) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the console command options. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
protected function getOptions() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
['model', 'm', InputOption::VALUE_OPTIONAL, 'The name of the model'], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the default namespace for the class. |
77
|
|
|
* |
78
|
|
|
* @param string $rootNamespace |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
protected function getDefaultNamespace($rootNamespace) |
82
|
|
|
{ |
83
|
|
|
return $this->repository->getModuleNamespace($this->module); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|