|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains the Modules Command class. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2016 Attila Fulop |
|
6
|
|
|
* @author Attila Fulop |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
* @since 2016-08-14 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Konekt\Concord\Console\Commands; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Console\Command; |
|
15
|
|
|
use Illuminate\Support\Collection; |
|
16
|
|
|
use Konekt\Concord\BaseModuleServiceProvider; |
|
17
|
|
|
use Konekt\Concord\Contracts\Concord; |
|
18
|
|
|
|
|
19
|
|
|
class ModulesCommand extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
protected $signature = 'concord:modules {--a|all : List all modules, including implicit ones}'; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
protected $description = 'List Concord Modules'; |
|
26
|
|
|
|
|
27
|
|
|
/** @var array */ |
|
28
|
|
|
protected $headers = ['#', 'Name', 'Kind', 'Version', 'Id', 'Namespace']; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Execute the command. |
|
32
|
|
|
* |
|
33
|
|
|
* @param Concord $concord |
|
34
|
|
|
* |
|
35
|
|
|
* @return mixed |
|
36
|
|
|
*/ |
|
37
|
|
|
public function handle(Concord $concord) |
|
38
|
|
|
{ |
|
39
|
|
|
$modules = $concord->getModules($this->option('all')); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
if ($modules->count()) { |
|
42
|
|
|
$this->showModules($modules); |
|
43
|
|
|
} else { |
|
44
|
|
|
$this->line('No modules have been registered. Add one in config/concord.php.'); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Displays the list of modules on the output |
|
50
|
|
|
* |
|
51
|
|
|
* @param $modules Collection |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function showModules(Collection $modules) |
|
54
|
|
|
{ |
|
55
|
|
|
$table = []; |
|
56
|
|
|
$i = 0; |
|
57
|
|
|
|
|
58
|
|
|
/** @var BaseModuleServiceProvider $module */ |
|
59
|
|
|
foreach ($modules as $module) { |
|
60
|
|
|
$i++; |
|
61
|
|
|
|
|
62
|
|
|
$table[] = [ |
|
63
|
|
|
'no' => sprintf('%d.', $i), |
|
64
|
|
|
'name' => $module->getManifest()->getName(), |
|
65
|
|
|
'kind' => $module->getKind()->label(), |
|
66
|
|
|
'version' => $module->getManifest()->getVersion(), |
|
67
|
|
|
'id' => $module->getId(), |
|
68
|
|
|
'namespace' => $module->getNamespaceRoot() |
|
69
|
|
|
]; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$this->table($this->headers, $table); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|