-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathModelCommand.php
More file actions
125 lines (106 loc) · 2.98 KB
/
Copy pathModelCommand.php
File metadata and controls
125 lines (106 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace Pingpong\Modules\Commands;
use Illuminate\Support\Str;
use Pingpong\Support\Stub;
use Pingpong\Modules\Traits\ModuleCommandTrait;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class ModelCommand extends GeneratorCommand
{
use ModuleCommandTrait;
/**
* The name of argument name.
*
* @var string
*/
protected $argumentName = 'model';
/**
* The console command name.
*
* @var string
*/
protected $name = 'module:make-model';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate new model for the specified module.';
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('model', InputArgument::REQUIRED, 'The name of model will be created.'),
array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('fillable', null, InputOption::VALUE_OPTIONAL, 'The fillable attributes.', null),
);
}
/**
* @return mixed
*/
protected function getTemplateContents()
{
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
return (new Stub('/model.stub', [
'NAME' => $this->getModelName(),
'FILLABLE' => $this->getFillable(),
'NAMESPACE' => $this->getClassNamespace($module),
'CLASS' => $this->getClass(),
'LOWER_NAME' => $module->getLowerName(),
'MODULE' => $this->getModuleName(),
'STUDLY_NAME' => $module->getStudlyName(),
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'),
]))->render();
}
/**
* @return mixed
*/
protected function getDestinationFilePath()
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
$seederPath = $this->laravel['modules']->config('paths.generator.model');
return $path.$seederPath.'/'.$this->getModelName().'.php';
}
/**
* @return mixed|string
*/
private function getModelName()
{
return Str::studly($this->argument('model'));
}
/**
* @return string
*/
private function getFillable()
{
$fillable = $this->option('fillable');
if (!is_null($fillable)) {
$arrays = explode(',', $fillable);
return json_encode($arrays);
}
return '[]';
}
/**
* Get default namespace.
*
* @return string
*/
public function getDefaultNamespace()
{
return $this->laravel['modules']->config('paths.generator.model');
}
}