forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigDebugCommand.php
More file actions
78 lines (68 loc) · 2.25 KB
/
Copy pathConfigDebugCommand.php
File metadata and controls
78 lines (68 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\ConfigDebugCommand.
*/
namespace Drupal\AppConsole\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Component\Serialization\Yaml;
class ConfigDebugCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('config:debug')
->setDescription($this->trans('commands.config.debug.description'))
->addArgument('config-name', InputArgument::OPTIONAL,
$this->trans('commands.config.debug.arguments.config-name'));
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$config_name = $input->getArgument('config-name');
$table = $this->getHelperSet()->get('table');
$table->setlayout($table::LAYOUT_COMPACT);
if (!$config_name) {
$this->getAllConfigurations($output, $table);
} else {
$this->getConfigurationByName($output, $table, $config_name);
}
}
/**
* @param $output OutputInterface
* @param $table TableHelper
*/
private function getAllConfigurations($output, $table)
{
$configFactory = $this->getConfigFactory();
$names = $configFactory->listAll();
$table->setHeaders([$this->trans('commands.config.debug.arguments.config-name')]);
foreach ($names as $name) {
$table->addRow([$name]);
}
$table->render($output);
}
/**
* @param $output OutputInterface
* @param $table TableHelper
* @param $config_name String
*/
private function getConfigurationByName($output, $table, $config_name)
{
$configStorage = $this->getConfigStorage();
if ($configStorage->exists($config_name)) {
$table->setHeaders([$config_name]);
$configuration = $configStorage->read($config_name);
$configurationEncoded = Yaml::encode($configuration);
$table->addRow([$configurationEncoded]);
}
$table->render($output);
}
}