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
|
|
|
public function handle() |
28
|
|
|
{ |
29
|
|
|
$this->table(['Name', 'Status', 'Order', 'Path'], $this->getRows()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get table rows. |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
public function getRows() |
38
|
|
|
{ |
39
|
|
|
$rows = []; |
40
|
|
|
|
41
|
|
|
foreach ($this->getModules() as $module) { |
42
|
|
|
$rows[] = [ |
43
|
|
|
$module->getName(), |
44
|
|
|
$module->enabled() ? 'Enabled' : 'Disabled', |
45
|
|
|
$module->get('order'), |
46
|
|
|
$module->getPath(), |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $rows; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getModules() |
54
|
|
|
{ |
55
|
|
|
switch ($this->option('only')) { |
56
|
|
|
case 'enabled': |
57
|
|
|
return $this->laravel['modules']->getByStatus(1); |
58
|
|
|
break; |
|
|
|
|
59
|
|
|
|
60
|
|
|
case 'disabled': |
61
|
|
|
return $this->laravel['modules']->getByStatus(0); |
62
|
|
|
break; |
|
|
|
|
63
|
|
|
|
64
|
|
|
case 'ordered': |
65
|
|
|
return $this->laravel['modules']->getOrdered($this->option('direction')); |
66
|
|
|
break; |
|
|
|
|
67
|
|
|
|
68
|
|
|
default: |
69
|
|
|
return $this->laravel['modules']->all(); |
70
|
|
|
break; |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get the console command options. |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
56 |
|
protected function getOptions() |
80
|
|
|
{ |
81
|
|
|
return array( |
82
|
56 |
|
array('only', null, InputOption::VALUE_OPTIONAL, 'Types of modules will be displayed.', null), |
83
|
|
|
array('direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'), |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.