-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathChainCommand.php
91 lines (76 loc) · 2.33 KB
/
ChainCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* @file
* Contains \Drupal\Console\Core\Command\Debug\ChainCommand.
*/
namespace Drupal\Console\Core\Command\Debug;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Core\Utils\ChainDiscovery;
/**
* Class ChainCommand
*
* @package Drupal\Console\Core\Command\Debug
*/
class ChainCommand extends Command
{
/**
* @var ChainDiscovery
*/
protected $chainDiscovery;
/**
* ChainCommand constructor.
*
* @param ChainDiscovery $chainDiscovery
*/
public function __construct(
ChainDiscovery $chainDiscovery
) {
$this->chainDiscovery = $chainDiscovery;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('debug:chain')
->setDescription($this->trans('commands.debug.chain.description'))
->setAliases(['dch']);
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$files = $this->chainDiscovery->getFiles();
$filesPerDirectory = $this->chainDiscovery->getFilesPerDirectory();
if (!$files || !$filesPerDirectory) {
$this->getIo()->warning($this->trans('commands.debug.chain.messages.no-files'));
return 0;
}
foreach ($filesPerDirectory as $directory => $fileNames) {
$this->getIo()->info(' ' . $this->trans('commands.debug.chain.messages.directory'), false);
$this->getIo()->comment($directory);
$tableHeader = [
$this->trans('commands.debug.chain.messages.file'),
$this->trans('commands.debug.chain.messages.command')
];
$tableRows = [];
foreach ($fileNames as $file) {
$commandName = '';
if (array_key_exists('command', $files[$directory.$file])) {
$commandName = $files[$directory.$file]['command'];
}
$tableRows[] = [
'file' => $file,
'command' => $commandName
];
}
$this->getIo()->table($tableHeader, $tableRows);
}
return 0;
}
}