|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Milkmeowo\Framework\Repository\Generators\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Milkmeowo\Framework\Repository\Generators\PresenterGenerator; |
|
10
|
|
|
use Milkmeowo\Framework\Repository\Generators\TransformerGenerator; |
|
11
|
|
|
use Milkmeowo\Framework\Repository\Generators\Exceptions\FileAlreadyExistsException; |
|
12
|
|
|
|
|
13
|
|
|
class PresenterCommand extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The name of command. |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $name = 'starter:presenter'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The description of command. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $description = 'Create a new presenter.'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The type of class being generated. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $type = 'Presenter'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the command. |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
|
|
public function fire() |
|
42
|
|
|
{ |
|
43
|
|
|
try { |
|
44
|
|
|
(new PresenterGenerator([ |
|
45
|
|
|
'name' => $this->argument('name'), |
|
46
|
|
|
'force' => $this->option('force'), |
|
47
|
|
|
]))->run(); |
|
48
|
|
|
$this->info('Presenter created successfully.'); |
|
49
|
|
|
|
|
50
|
|
|
$filesystem = new Filesystem(); |
|
51
|
|
|
|
|
52
|
|
|
if (! $filesystem->exists(app()->path().'/Transformers/'.$this->argument('name').'Transformer.php')) { |
|
53
|
|
|
(new TransformerGenerator([ |
|
54
|
|
|
'name' => $this->argument('name'), |
|
55
|
|
|
'force' => $this->option('force'), |
|
56
|
|
|
]))->run(); |
|
57
|
|
|
$this->info('Transformer created successfully.'); |
|
58
|
|
|
} |
|
59
|
|
|
} catch (FileAlreadyExistsException $e) { |
|
60
|
|
|
$this->error($this->type.' already exists!'); |
|
61
|
|
|
|
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* The array of command arguments. |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getArguments() |
|
72
|
|
|
{ |
|
73
|
|
|
return [ |
|
74
|
|
|
[ |
|
75
|
|
|
'name', |
|
76
|
|
|
InputArgument::REQUIRED, |
|
77
|
|
|
'The name of model for which the presenter is being generated.', |
|
78
|
|
|
null, |
|
79
|
|
|
], |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* The array of command options. |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getOptions() |
|
89
|
|
|
{ |
|
90
|
|
|
return [ |
|
91
|
|
|
[ |
|
92
|
|
|
'force', |
|
93
|
|
|
'f', |
|
94
|
|
|
InputOption::VALUE_NONE, |
|
95
|
|
|
'Force the creation if file already exists.', |
|
96
|
|
|
null, |
|
97
|
|
|
], |
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|