|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Nwidart\Modules\Contracts\ActivatorInterface; |
|
7
|
|
|
use Nwidart\Modules\Generators\ModuleGenerator; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
|
|
11
|
|
|
class ModuleMakeCommand extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The console command name. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $name = 'module:make'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'Create a new module.'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Execute the console command. |
|
29
|
|
|
*/ |
|
30
|
130 |
|
public function handle() : int |
|
31
|
|
|
{ |
|
32
|
130 |
|
$names = $this->argument('name'); |
|
33
|
130 |
|
$success = true; |
|
34
|
|
|
|
|
35
|
130 |
|
foreach ($names as $name) { |
|
|
|
|
|
|
36
|
130 |
|
$type = $this->getModuleType($this->option('plain'),$this->option('api'),$this->option('web')); |
|
37
|
130 |
|
$code = with(new ModuleGenerator($name)) |
|
38
|
130 |
|
->setFilesystem($this->laravel['files']) |
|
39
|
130 |
|
->setModule($this->laravel['modules']) |
|
40
|
130 |
|
->setConfig($this->laravel['config']) |
|
41
|
130 |
|
->setActivator($this->laravel[ActivatorInterface::class]) |
|
42
|
130 |
|
->setConsole($this) |
|
43
|
130 |
|
->setForce($this->option('force')) |
|
44
|
130 |
|
->setType($type) |
|
45
|
130 |
|
->setActive(!$this->option('disabled')) |
|
46
|
|
|
->generate(); |
|
47
|
130 |
|
|
|
48
|
1 |
|
if ($code === E_ERROR) { |
|
49
|
|
|
$success = false; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
130 |
|
|
|
53
|
|
|
return $success ? 0 : E_ERROR; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the console command arguments. |
|
58
|
|
|
* |
|
59
|
|
|
* @return array |
|
60
|
130 |
|
*/ |
|
61
|
|
|
protected function getArguments() |
|
62
|
|
|
{ |
|
63
|
130 |
|
return [ |
|
64
|
|
|
['name', InputArgument::IS_ARRAY, 'The names of modules will be created.'], |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
130 |
|
|
|
68
|
|
|
protected function getOptions() |
|
69
|
|
|
{ |
|
70
|
130 |
|
return [ |
|
71
|
|
|
['plain', 'p', InputOption::VALUE_NONE, 'Generate a plain module (without some resources).'], |
|
72
|
|
|
['api', null, InputOption::VALUE_NONE, 'Generate an api module.'], |
|
73
|
|
|
['web', null, InputOption::VALUE_NONE, 'Generate a web module.'], |
|
74
|
|
|
['disabled', 'd', InputOption::VALUE_NONE, 'Do not enable the module at creation.'], |
|
75
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when the module already exists.'], |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
private function getModuleType($isPlain,$isApi,$isWeb){ |
|
80
|
|
|
return ($isPlain && $isApi && $isWeb)||($isPlain && $isApi)||($isApi && $isWeb)||($isPlain && $isWeb)?'web':($isPlain&&(!$isApi&&!$isWeb)?'plain':($isApi&&(!$isPlain&&!$isWeb)?'api':'web')); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.