Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / drupal / console-core / src / Command / Debug / SiteCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Core\Command\Debug\SiteCommand.
6  */
7
8 namespace Drupal\Console\Core\Command\Debug;
9
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Yaml\Dumper;
14 use Drupal\Console\Core\Command\Command;
15 use Drupal\Console\Core\Utils\ConfigurationManager;
16
17 /**
18  * Class SiteCommand
19  *
20  * @package Drupal\Console\Core\Command\Debug
21  */
22 class SiteCommand extends Command
23 {
24     /**
25      * @var ConfigurationManager
26      */
27     protected $configurationManager;
28
29     /**
30      * SiteCommand constructor.
31      *
32      * @param ConfigurationManager $configurationManager
33      */
34     public function __construct(
35         ConfigurationManager $configurationManager
36     ) {
37         $this->configurationManager = $configurationManager;
38         parent::__construct();
39     }
40
41     /**
42      * @{@inheritdoc}
43      */
44     public function configure()
45     {
46         $this
47             ->setName('debug:site')
48             ->setDescription($this->trans('commands.debug.site.description'))
49             ->addArgument(
50                 'target',
51                 InputArgument::OPTIONAL,
52                 $this->trans('commands.debug.site.options.target'),
53                 null
54             )
55             ->addArgument(
56                 'property',
57                 InputArgument::OPTIONAL,
58                 $this->trans('commands.debug.site.options.property'),
59                 null
60             )
61             ->setHelp($this->trans('commands.debug.site.help'))
62             ->setAliases(['dsi']);
63     }
64
65     /**
66      * {@inheritdoc}
67      */
68     protected function execute(InputInterface $input, OutputInterface $output)
69     {
70         $sites = $this->configurationManager->getSites();
71
72         if (!$sites) {
73             $this->getIo()->warning($this->trans('commands.debug.site.messages.invalid-sites'));
74
75             return 0;
76         }
77
78         $target = $input->getArgument('target');
79         if (!$target) {
80             foreach ($sites as $key => $site) {
81                 $environments = array_keys($site);
82                 unset($environments[0]);
83
84                 $environments = array_map(
85                     function ($element) use ($key) {
86                         return $key . '.' . $element;
87                     },
88                     $environments
89                 );
90
91                 $this->getIo()->info($key);
92                 $this->getIo()->listing($environments);
93             }
94
95             return 0;
96         }
97
98         $targetConfig = $this->configurationManager->readTarget($target);
99         if (!$targetConfig) {
100             $this->getIo()->error($this->trans('commands.debug.site.messages.invalid-site'));
101
102             return 1;
103         }
104
105         // --property argument, allows the user to fetch specific properties of the selected site
106         $property = $input->getArgument('property');
107         if ($property) {
108             $property_keys = explode('.', $property);
109
110             $val = $targetConfig;
111             foreach ($property_keys as $property_key) {
112                 $val = &$val[$property_key];
113             }
114
115             $this->getIo()->writeln($val);
116             return 0;
117         }
118
119         $this->getIo()->info($target);
120         $dumper = new Dumper();
121         $this->getIo()->writeln($dumper->dump($targetConfig, 4, 2));
122
123         return 0;
124     }
125 }