1 | <?php |
||
11 | class DatatableMakeCommand extends GeneratorCommand |
||
12 | { |
||
13 | /** |
||
14 | * The console command name. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $name = 'datatable:make'; |
||
19 | |||
20 | /** |
||
21 | * The console command description. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $description = 'Creates a datable builder class.'; |
||
26 | |||
27 | /** |
||
28 | * The filesystem instance. |
||
29 | * |
||
30 | * @var \Illuminate\Filesystem\Filesystem |
||
31 | */ |
||
32 | protected $files; |
||
33 | |||
34 | /** |
||
35 | * Datatable generator instance. |
||
36 | * |
||
37 | * @var \Distilleries\DatatableBuilder\Console\Lib\Generators\DatatableGenerator |
||
38 | */ |
||
39 | protected $formGenerator; |
||
40 | |||
41 | /** |
||
42 | * DatatableMakeCommand constructor. |
||
43 | * |
||
44 | * @param \Illuminate\Filesystem\Filesystem $files |
||
45 | * @param \Distilleries\DatatableBuilder\Console\Lib\Generators\DatatableGenerator $formGenerator |
||
46 | */ |
||
47 | 16 | public function __construct(Filesystem $files, DatatableGenerator $formGenerator) |
|
48 | { |
||
49 | 16 | parent::__construct($files); |
|
50 | |||
51 | 16 | $this->formGenerator = $formGenerator; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get the console command arguments. |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | 16 | protected function getArguments() |
|
65 | |||
66 | /** |
||
67 | * Get the console command options. |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | 16 | protected function getOptions() |
|
72 | { |
||
73 | return [ |
||
74 | 16 | ['fields', null, InputOption::VALUE_OPTIONAL, 'Fields for the datatable'], |
|
75 | ]; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Replace the class name for the given stub. |
||
80 | * |
||
81 | * @param string $stub |
||
82 | * @param string $name |
||
83 | * @return string |
||
84 | */ |
||
85 | 8 | protected function replaceClass($stub, $name) |
|
86 | { |
||
87 | 8 | $formGenerator = $this->formGenerator; |
|
88 | |||
89 | 8 | $stub = str_replace( |
|
90 | 8 | '{{class}}', |
|
91 | 8 | $formGenerator->getClassInfo($name)->className, |
|
92 | 8 | $stub |
|
93 | ); |
||
94 | |||
95 | 8 | return str_replace( |
|
96 | 8 | '{{fields}}', |
|
97 | 8 | $formGenerator->getFieldsVariable($this->option('fields')), |
|
98 | 8 | $stub |
|
99 | ); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Replace the namespace for the given stub. |
||
104 | * |
||
105 | * @param string $stub |
||
106 | * @param string $name |
||
107 | * @return $this |
||
108 | */ |
||
109 | 8 | protected function replaceNamespace(&$stub, $name) |
|
110 | { |
||
111 | 8 | $stub = str_replace( |
|
112 | 8 | '{{namespace}}', |
|
113 | 8 | $this->formGenerator->getClassInfo($name)->namespace, |
|
114 | 8 | $stub |
|
115 | ); |
||
116 | |||
117 | 8 | return $this; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * Get the desired class name from the input. |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | 12 | protected function getNameInput() |
|
129 | |||
130 | /** |
||
131 | * Get the stub file for the generator. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | 8 | protected function getStub() |
|
139 | } |
||
140 |