|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelPlus\Extension\Generators\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Jumilla\Generators\Laravel\OneFileGeneratorCommand as BaseCommand; |
|
6
|
|
|
use Jumilla\Generators\FileGenerator; |
|
7
|
|
|
use LaravelPlus\Extension\Addons\Addon; |
|
8
|
|
|
use LaravelPlus\Extension\Generators\GeneratorCommandTrait; |
|
9
|
|
|
use Illuminate\Support\Str; |
|
10
|
|
|
|
|
11
|
|
|
class ModelMakeCommand extends BaseCommand |
|
12
|
|
|
{ |
|
13
|
|
|
use GeneratorCommandTrait; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The console command singature. |
|
17
|
|
|
* |
|
18
|
|
|
* @var stringphp |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $signature = 'make:model |
|
21
|
|
|
{name : The name of the class} |
|
22
|
|
|
{--a|addon= : The name of the addon} |
|
23
|
|
|
{--m|migration= : Create a new migration file for the model} |
|
24
|
|
|
'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The console command description. |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $description = '[+] Create a new Eloquent model class'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The type of class being generated. |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $type = 'Model'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The constructor. |
|
42
|
|
|
*/ |
|
43
|
6 |
|
public function __construct() |
|
44
|
|
|
{ |
|
45
|
6 |
|
parent::__construct(); |
|
46
|
|
|
|
|
47
|
6 |
|
$this->setStubDirectory(__DIR__.'/../stubs'); |
|
48
|
6 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Execute the console command. |
|
52
|
|
|
*/ |
|
53
|
4 |
|
public function handle() |
|
54
|
|
|
{ |
|
55
|
4 |
|
$this->addon = $this->getAddon(); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
3 |
|
if (parent::handle() !== false) { |
|
58
|
3 |
|
if ($this->option('migration')) { |
|
59
|
1 |
|
$table = $this->toTable($this->argument('name')); |
|
60
|
|
|
|
|
61
|
1 |
|
$this->call('make:migration', [ |
|
62
|
1 |
|
'name' => $this->option('migration'), |
|
63
|
1 |
|
'--addon' => $this->option('addon'), |
|
64
|
1 |
|
'--create' => $table, |
|
65
|
|
|
]); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
3 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get the default namespace for the class. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
3 |
|
protected function getDefaultNamespace() |
|
76
|
|
|
{ |
|
77
|
3 |
|
return $this->getRootNamespace(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get the stub file for the generator. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
3 |
|
protected function getStub() |
|
86
|
|
|
{ |
|
87
|
3 |
|
return 'model.stub'; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Generate file. |
|
92
|
|
|
* |
|
93
|
|
|
* @param \Jumilla\Generators\FileGenerator $generator |
|
94
|
|
|
* @param string $path |
|
95
|
|
|
* @param string $fqcn |
|
96
|
|
|
* |
|
97
|
|
|
* @return bool |
|
98
|
|
|
*/ |
|
99
|
3 |
|
protected function generateFile(FileGenerator $generator, $path, $fqcn) |
|
100
|
|
|
{ |
|
101
|
3 |
|
list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); |
|
102
|
|
|
|
|
103
|
3 |
|
return $generator->file($path)->template($this->getStub(), [ |
|
104
|
3 |
|
'namespace' => $namespace, |
|
105
|
3 |
|
'class' => $class, |
|
106
|
3 |
|
'table' => $this->toTable($class), |
|
107
|
|
|
]); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Convert name to table. |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $name |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
3 |
|
protected function toTable($name) |
|
118
|
|
|
{ |
|
119
|
3 |
|
return Str::plural(Str::snake(class_basename($name))); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..