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