5 * Contains \Drupal\Console\Core\Command\Debug\SiteCommand.
8 namespace Drupal\Console\Core\Command\Debug;
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;
20 * @package Drupal\Console\Core\Command\Debug
22 class SiteCommand extends Command
25 * @var ConfigurationManager
27 protected $configurationManager;
30 * SiteCommand constructor.
32 * @param ConfigurationManager $configurationManager
34 public function __construct(
35 ConfigurationManager $configurationManager
37 $this->configurationManager = $configurationManager;
38 parent::__construct();
44 public function configure()
47 ->setName('debug:site')
48 ->setDescription($this->trans('commands.debug.site.description'))
51 InputArgument::OPTIONAL,
52 $this->trans('commands.debug.site.options.target'),
57 InputArgument::OPTIONAL,
58 $this->trans('commands.debug.site.options.property'),
61 ->setHelp($this->trans('commands.debug.site.help'))
62 ->setAliases(['dsi']);
68 protected function execute(InputInterface $input, OutputInterface $output)
70 $sites = $this->configurationManager->getSites();
73 $this->getIo()->warning($this->trans('commands.debug.site.messages.invalid-sites'));
78 $target = $input->getArgument('target');
80 foreach ($sites as $key => $site) {
81 $environments = array_keys($site);
82 unset($environments[0]);
84 $environments = array_map(
85 function ($element) use ($key) {
86 return $key . '.' . $element;
91 $this->getIo()->info($key);
92 $this->getIo()->listing($environments);
98 $targetConfig = $this->configurationManager->readTarget($target);
100 $this->getIo()->error($this->trans('commands.debug.site.messages.invalid-site'));
105 // --property argument, allows the user to fetch specific properties of the selected site
106 $property = $input->getArgument('property');
108 $property_keys = explode('.', $property);
110 $val = $targetConfig;
111 foreach ($property_keys as $property_key) {
112 $val = &$val[$property_key];
115 $this->getIo()->writeln($val);
119 $this->getIo()->info($target);
120 $dumper = new Dumper();
121 $this->getIo()->writeln($dumper->dump($targetConfig, 4, 2));