|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rougin\Combustor\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Rougin\Combustor\Common\Tools; |
|
6
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Create Scaffold Command |
|
14
|
|
|
* |
|
15
|
|
|
* Generates a Wildfire or Doctrine-based controller, |
|
16
|
|
|
* model and view files for CodeIgniter |
|
17
|
|
|
* |
|
18
|
|
|
* @package Combustor |
|
19
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class CreateScaffoldCommand extends AbstractCommand |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Checks whether the command is enabled or not in the current environment. |
|
25
|
|
|
* |
|
26
|
|
|
* Override this to check for x or y and return false if the command can not |
|
27
|
|
|
* run properly under the current conditions. |
|
28
|
|
|
* |
|
29
|
|
|
* @return bool |
|
30
|
|
|
*/ |
|
31
|
6 |
|
public function isEnabled() |
|
32
|
|
|
{ |
|
33
|
6 |
|
return Tools::isCommandEnabled(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Sets the configurations of the specified command. |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
6 |
|
protected function configure() |
|
42
|
|
|
{ |
|
43
|
6 |
|
$this->setName('create:scaffold') |
|
44
|
6 |
|
->setDescription('Creates a new controller, model and view') |
|
45
|
6 |
|
->addArgument( |
|
46
|
6 |
|
'name', |
|
47
|
6 |
|
InputArgument::REQUIRED, |
|
48
|
|
|
'Name of the controller, model and view' |
|
49
|
6 |
|
)->addOption( |
|
50
|
6 |
|
'bootstrap', |
|
51
|
6 |
|
NULL, |
|
52
|
6 |
|
InputOption::VALUE_NONE, |
|
53
|
|
|
'Includes the Bootstrap CSS/JS Framework tags' |
|
54
|
6 |
|
)->addOption( |
|
55
|
6 |
|
'camel', |
|
56
|
6 |
|
NULL, |
|
57
|
6 |
|
InputOption::VALUE_NONE, |
|
58
|
|
|
'Uses the camel case naming convention' |
|
59
|
6 |
|
)->addOption( |
|
60
|
6 |
|
'doctrine', |
|
61
|
6 |
|
NULL, |
|
62
|
6 |
|
InputOption::VALUE_NONE, |
|
63
|
|
|
'Uses the Doctrine\'s specifications' |
|
64
|
6 |
|
)->addOption( |
|
65
|
6 |
|
'keep', |
|
66
|
6 |
|
null, |
|
67
|
6 |
|
InputOption::VALUE_NONE, |
|
68
|
|
|
'Keeps the name to be used' |
|
69
|
6 |
|
)->addOption( |
|
70
|
6 |
|
'lowercase', |
|
71
|
6 |
|
null, |
|
72
|
6 |
|
InputOption::VALUE_NONE, |
|
73
|
|
|
'Keeps the first character of the name to lowercase' |
|
74
|
6 |
|
)->addOption( |
|
75
|
6 |
|
'wildfire', |
|
76
|
6 |
|
NULL, |
|
77
|
6 |
|
InputOption::VALUE_NONE, |
|
78
|
|
|
'Uses the Wildfire\'s specifications' |
|
79
|
6 |
|
); |
|
80
|
6 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Executes the command. |
|
84
|
|
|
* |
|
85
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
86
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
87
|
|
|
* @return object|\Symfony\Component\Console\Output\OutputInterface |
|
88
|
|
|
*/ |
|
89
|
3 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
90
|
|
|
{ |
|
91
|
|
|
$commands = [ |
|
92
|
3 |
|
'create:controller', |
|
93
|
3 |
|
'create:model', |
|
94
|
|
|
'create:view' |
|
95
|
3 |
|
]; |
|
96
|
|
|
|
|
97
|
3 |
|
$bootstrap = $input->getOption('bootstrap'); |
|
98
|
3 |
|
$camel = $input->getOption('camel'); |
|
99
|
3 |
|
$doctrine = $input->getOption('doctrine'); |
|
100
|
3 |
|
$keep = $input->getOption('keep'); |
|
101
|
3 |
|
$lowercase = $input->getOption('lowercase'); |
|
|
|
|
|
|
102
|
3 |
|
$lowercase = $input->getOption('lowercase'); |
|
103
|
3 |
|
$wildfire = $input->getOption('wildfire'); |
|
104
|
|
|
|
|
105
|
3 |
|
foreach ($commands as $command) { |
|
106
|
|
|
$arguments = [ |
|
107
|
3 |
|
'command' => $command, |
|
108
|
3 |
|
'name' => $input->getArgument('name') |
|
109
|
3 |
|
]; |
|
110
|
|
|
|
|
111
|
|
|
switch ($command) { |
|
112
|
3 |
View Code Duplication |
case 'create:controller': |
|
|
|
|
|
|
113
|
3 |
|
$arguments['--camel'] = $camel; |
|
114
|
3 |
|
$arguments['--doctrine'] = $doctrine; |
|
115
|
3 |
|
$arguments['--keep'] = $keep; |
|
116
|
3 |
|
$arguments['--lowercase'] = $lowercase; |
|
117
|
3 |
|
$arguments['--wildfire'] = $wildfire; |
|
118
|
|
|
|
|
119
|
3 |
|
break; |
|
120
|
3 |
View Code Duplication |
case 'create:model': |
|
|
|
|
|
|
121
|
3 |
|
$arguments['--camel'] = $camel; |
|
122
|
3 |
|
$arguments['--doctrine'] = $doctrine; |
|
123
|
3 |
|
$arguments['--lowercase'] = $lowercase; |
|
124
|
3 |
|
$arguments['--wildfire'] = $wildfire; |
|
125
|
|
|
|
|
126
|
3 |
|
break; |
|
127
|
3 |
|
case 'create:view': |
|
128
|
3 |
|
$arguments['--bootstrap'] = $bootstrap; |
|
129
|
3 |
|
$arguments['--camel'] = $camel; |
|
130
|
3 |
|
$arguments['--keep'] = $keep; |
|
131
|
|
|
|
|
132
|
3 |
|
break; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
3 |
|
$input = new ArrayInput($arguments); |
|
136
|
3 |
|
$application = $this->getApplication()->find($command); |
|
137
|
3 |
|
$application->run($input, $output); |
|
138
|
3 |
|
} |
|
139
|
3 |
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.