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