1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
7
|
|
|
|
8
|
|
|
class ListCommand extends Command |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The console command name. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $name = 'module:list'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The console command description. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $description = 'Show list of all modules.'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Execute the console command. |
26
|
|
|
* |
27
|
|
|
* @return mixed |
28
|
|
|
*/ |
29
|
|
|
public function fire() |
30
|
|
|
{ |
31
|
|
|
$this->table(['Name', 'Status', 'Order', 'Path'], $this->getRows()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get table rows. |
36
|
|
|
* |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
public function getRows() |
40
|
|
|
{ |
41
|
|
|
$rows = []; |
42
|
|
|
|
43
|
|
|
foreach ($this->getModules() as $module) { |
44
|
|
|
$rows[] = [ |
45
|
|
|
$module->getStudlyName(), |
46
|
|
|
$module->enabled() ? 'Enabled' : 'Disabled', |
47
|
|
|
$module->get('order'), |
48
|
|
|
$module->getPath(), |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $rows; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getModules() |
56
|
|
|
{ |
57
|
|
|
switch ($this->option('only')) { |
58
|
|
|
case 'enabled': |
59
|
|
|
return $this->laravel['modules']->getByStatus(1); |
60
|
|
|
break; |
|
|
|
|
61
|
|
|
|
62
|
|
|
case 'disabled': |
63
|
|
|
return $this->laravel['modules']->getByStatus(0); |
64
|
|
|
break; |
|
|
|
|
65
|
|
|
|
66
|
|
|
case 'ordered': |
67
|
|
|
return $this->laravel['modules']->getOrdered($this->option('direction')); |
68
|
|
|
break; |
|
|
|
|
69
|
|
|
|
70
|
|
|
default: |
71
|
|
|
return $this->laravel['modules']->all(); |
72
|
|
|
break; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the console command options. |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
16 |
|
protected function getOptions() |
82
|
|
|
{ |
83
|
|
|
return array( |
84
|
16 |
|
array('only', null, InputOption::VALUE_OPTIONAL, 'Types of modules will be displayed.', null), |
85
|
16 |
|
array('direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'), |
86
|
16 |
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.