5 * Contains \Drupal\Console\Command\Debug\ConfigCommand.
8 namespace Drupal\Console\Command\Debug;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Drupal\Component\Serialization\Yaml;
15 use Drupal\Core\Config\CachedStorage;
16 use Drupal\Core\Config\ConfigFactory;
17 use Drupal\Console\Core\Command\Command;
19 class ConfigCommand extends Command
24 protected $configFactory;
29 protected $configStorage;
32 * ConfigCommand constructor.
34 * @param ConfigFactory $configFactory
35 * @param CachedStorage $configStorage
37 public function __construct(
38 ConfigFactory $configFactory,
39 CachedStorage $configStorage
41 $this->configFactory = $configFactory;
42 $this->configStorage = $configStorage;
43 parent::__construct();
49 protected function configure()
52 ->setName('debug:config')
53 ->setDescription($this->trans('commands.debug.config.description'))
56 InputArgument::OPTIONAL,
57 $this->trans('commands.debug.config.arguments.name')
62 InputOption::VALUE_NONE,
63 $this->trans('commands.debug.config.options.show-overridden')
71 protected function execute(InputInterface $input, OutputInterface $output)
73 $configName = $input->getArgument('name');
74 $showOverridden = $input->getOption('show-overridden');
77 $this->getAllConfigurations();
79 $this->getConfigurationByName($configName, $showOverridden);
83 private function getAllConfigurations()
85 $names = $this->configFactory->listAll();
87 $this->trans('commands.debug.config.arguments.name'),
90 foreach ($names as $name) {
96 $this->getIo()->table($tableHeader, $tableRows, 'compact');
100 * @param $config_name String
101 * @param $showOverridden bool
103 private function getConfigurationByName($config_name, $showOverridden = false)
105 if ($this->configStorage->exists($config_name)) {
109 $configuration = $this->configStorage->read($config_name);
110 if ($showOverridden) {
111 $configurationKeys = array_keys($configuration);
112 foreach ($configurationKeys as $configurationKey) {
113 $configuration[$configurationKey] = $this->configFactory
115 ->get($configurationKey);
119 $configurationEncoded = Yaml::encode($configuration);
122 $configurationEncoded,
125 $this->getIo()->table($tableHeader, $tableRows, 'compact');
127 $this->getIo()->error(
128 sprintf($this->trans('commands.debug.config.errors.not-exists'), $config_name)