1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Nwidart\Modules\Support\Config\GenerateConfigReader; |
7
|
|
|
use Nwidart\Modules\Support\Stub; |
8
|
|
|
use Nwidart\Modules\Traits\ModuleCommandTrait; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
|
11
|
|
|
class FactoryMakeCommand extends GeneratorCommand |
12
|
|
|
{ |
13
|
|
|
use ModuleCommandTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The name of argument name. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $argumentName = 'name'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command name. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $name = 'module:make-factory'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The console command description. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $description = 'Create a new model factory for the specified module.'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the console command arguments. |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
protected function getArguments() |
42
|
|
|
{ |
43
|
|
|
return [ |
44
|
|
|
['name', InputArgument::REQUIRED, 'The name of the factory.'], |
45
|
|
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
|
|
protected function getTemplateContents() |
53
|
|
|
{ |
54
|
|
|
return (new Stub('/factory.stub'))->render(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return mixed |
59
|
|
|
*/ |
60
|
|
|
protected function getDestinationFilePath() |
61
|
|
|
{ |
62
|
|
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
63
|
|
|
|
64
|
|
|
$factoryPath = GenerateConfigReader::read('factory'); |
65
|
|
|
|
66
|
|
|
return $path . $factoryPath->getPath() . '/' . $this->getFileName(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
private function getFileName() |
73
|
|
|
{ |
74
|
|
|
return Str::studly($this->argument('name')) . '.php'; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|