Skip to content

Commit

Permalink
Debug settings display as yaml (#265)
Browse files Browse the repository at this point in the history
* [debug:settings] Change display as YAML dump.

* [debug:settings] Add application root.

* [debug:settings] Remove @console.nested_array service.
  • Loading branch information
jmolivas committed Jan 7, 2018
1 parent 7a31914 commit 9dd5350
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 58 deletions.
2 changes: 1 addition & 1 deletion services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ services:
- { name: drupal.command }
console.settings_debug:
class: Drupal\Console\Core\Command\Debug\SettingsCommand
arguments: ['@console.configuration_manager', '@console.nested_array']
arguments: ['@console.configuration_manager']
tags:
- { name: drupal.command }
console.settings_set:
Expand Down
71 changes: 14 additions & 57 deletions src/Command/Debug/SettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Core\Utils\ConfigurationManager;
use Drupal\Console\Core\Utils\NestedArray;
use Drupal\Console\Core\Style\DrupalStyle;
use Symfony\Component\Yaml\Yaml;

/**
* Class SettingsCommand
Expand All @@ -26,23 +26,15 @@ class SettingsCommand extends Command
*/
protected $configurationManager;

/**
* @var NestedArray
*/
protected $nestedArray;

/**
* CheckCommand constructor.
*
* @param ConfigurationManager $configurationManager
* @param NestedArray $nestedArray
*/
public function __construct(
ConfigurationManager $configurationManager,
NestedArray $nestedArray
ConfigurationManager $configurationManager
) {
$this->configurationManager = $configurationManager;
$this->nestedArray = $nestedArray;
parent::__construct();
}

Expand All @@ -66,56 +58,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);

$configuration = $this->configurationManager->getConfiguration();
$configApplication = $configuration->get('application');

unset($configApplication['autowire']);
unset($configApplication['languages']);
unset($configApplication['aliases']);
unset($configApplication['composer']);
unset($configApplication['default']['commands']);
$configApplication['application'] = $configuration->getRaw('application');

$configApplicationFlatten = [];
$keyFlatten = '';

$this->nestedArray->yamlFlattenArray(
$configApplication,
$configApplicationFlatten,
$keyFlatten
);

$tableHeader = [
$this->trans('commands.debug.settings.messages.config-key'),
$this->trans('commands.debug.settings.messages.config-value'),
];

$tableRows = [];
foreach ($configApplicationFlatten as $ymlKey => $ymlValue) {
$tableRows[] = [
$ymlKey,
$ymlValue
];
}

$io->newLine();
$io->info(
sprintf(
'%s :',
$this->trans('commands.debug.settings.messages.config-file')
),
false
);

$io->comment(
sprintf(
'%s/.console/config.yml',
$this->configurationManager->getHomeDirectory()
),
true
);
$io->write(Yaml::dump($configApplication, 6, 2));

$io->newLine();

$io->table($tableHeader, $tableRows, 'compact');
$io->info($this->trans('commands.debug.settings.messages.config-file'));

$configurationFiles = [];
foreach ($this->configurationManager->getConfigurationFiles() as $key => $configurationFile) {
$configurationFiles = array_merge(
$configurationFiles,
$configurationFile
);
}
$io->listing($configurationFiles);

return 0;
}
Expand Down
8 changes: 8 additions & 0 deletions src/Utils/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ public function getSites()
return $this->sites;
}

/**
* @return array
*/
public function getConfigurationFiles() {
return $this->configurationFiles;
}


public function getHomeDirectory()
{
return Path::getHomeDirectory();
Expand Down

0 comments on commit 9dd5350

Please sign in to comment.