Version 1
[yaffs-website] / vendor / drupal / console / src / Command / Multisite / DebugCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Site\DebugCommand.
6  */
7
8 namespace Drupal\Console\Command\Multisite;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Console\Core\Command\Shared\CommandTrait;
14 use Drupal\Console\Core\Style\DrupalStyle;
15
16 /**
17  * Class SiteDebugCommand
18  *
19  * @package Drupal\Console\Command\Site
20  */
21 class DebugCommand extends Command
22 {
23     use CommandTrait;
24
25     protected $appRoot;
26
27     /**
28      * DebugCommand constructor.
29      *
30      * @param $appRoot
31      */
32     public function __construct($appRoot)
33     {
34         $this->appRoot = $appRoot;
35         parent::__construct();
36     }
37
38     /**
39      * {@inheritdoc}
40      */
41     public function configure()
42     {
43         $this
44             ->setName('multisite:debug')
45             ->setDescription($this->trans('commands.multisite.debug.description'))
46             ->setHelp($this->trans('commands.multisite.debug.help'));
47         ;
48     }
49
50     /**
51      * {@inheritdoc}
52      */
53     protected function execute(InputInterface $input, OutputInterface $output)
54     {
55         $io = new DrupalStyle($input, $output);
56
57         $sites = [];
58
59         $multiSiteFile = sprintf(
60             '%s/sites/sites.php',
61             $this->appRoot
62         );
63
64         if (file_exists($multiSiteFile)) {
65             include $multiSiteFile;
66         }
67
68         if (!$sites) {
69             $io->error(
70                 $this->trans('commands.multisite.debug.messages.no-multisites')
71             );
72
73             return 1;
74         }
75
76         $io->info(
77             $this->trans('commands.multisite.debug.messages.site-format')
78         );
79
80         $tableHeader = [
81             $this->trans('commands.multisite.debug.messages.site'),
82             $this->trans('commands.multisite.debug.messages.directory'),
83         ];
84
85         $tableRows = [];
86         foreach ($sites as $site => $directory) {
87             $tableRows[] = [
88                 $site,
89                 $this->appRoot  . '/sites/' . $directory
90             ];
91         }
92
93         $io->table($tableHeader, $tableRows);
94
95         return 0;
96     }
97 }