|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the EasyWeChatComposer. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) 张铭阳 <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* This source file is subject to the MIT license that is bundled |
|
11
|
|
|
* with this source code in the file LICENSE. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace EasyWeChatComposer\Commands; |
|
15
|
|
|
|
|
16
|
|
|
use Composer\Command\BaseCommand; |
|
17
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
|
|
21
|
|
|
class ExtensionsCommand extends BaseCommand |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Configures the current command. |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->setName('easywechat:extensions') |
|
29
|
|
|
->setDescription('Lists all installed extensions.'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Executes the current command. |
|
34
|
|
|
* |
|
35
|
|
|
* @param InputInterface $input |
|
36
|
|
|
* @param OutputInterface $output |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
39
|
|
|
{ |
|
40
|
|
|
$extensions = require __DIR__.'/../../extensions.php'; |
|
41
|
|
|
|
|
42
|
|
|
if (empty($extensions) || !is_array($extensions)) { |
|
43
|
|
|
return $output->writeln('<info>No extension installed.</info>'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$table = new Table($output); |
|
47
|
|
|
$table->setHeaders(['Name', 'Observers']) |
|
48
|
|
|
->setRows( |
|
49
|
|
|
array_map([$this, 'getRows'], array_keys($extensions), $extensions) |
|
50
|
|
|
)->render(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param string $name |
|
55
|
|
|
* @param array $extension |
|
56
|
|
|
* |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function getRows($name, $extension) |
|
60
|
|
|
{ |
|
61
|
|
|
return [$name, implode("\n", $extension['observers'] ?? [])]; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|