Skip to content

Commit

Permalink
Issue hechoendrupal#2766: add a container:parameters command.
Browse files Browse the repository at this point in the history
  • Loading branch information
fgm committed Oct 5, 2016
1 parent 9b0de9e commit e4e6062
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/services/drupal-console/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ services:
class: Drupal\Console\Command\ContainerDebugCommand
tags:
- { name: drupal.command }
console.parameters_debug:
class: Drupal\Console\Command\ContainerParametersCommand
tags:
- { name: drupal.command }
console.plugin_debug:
class: Drupal\Console\Command\PluginDebugCommand
tags:
Expand Down
64 changes: 64 additions & 0 deletions src/Command/ContainerParametersCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* @file
* Contains \Drupal\Console\Command\ContainerParametersCommand.
*/

namespace Drupal\Console\Command;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
use Drupal\Console\Style\DrupalStyle;
use Symfony\Component\Yaml\Yaml;

/**
* Class ContainerParametersCommand
*
* @package Drupal\Console\Command
*/
class ContainerParametersCommand extends Command {
use ContainerAwareCommandTrait;

/**
* {@inheritdoc}
*/
protected function configure() {
$this
->setName('container:parameters')
->setDescription($this->trans('commands.container.parameters.description'));
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$io = new DrupalStyle($input, $output);

$parametersList = $this->getParametersList();
ksort($parametersList);
$parameters = ['parameters' => $parametersList];
$io->write(Yaml::dump($parameters, 4, 2));
return 0;
}

private function getParametersList() {
$parameters = array_filter($this->container->getParameterBag()->all(), function ($name) {
if (preg_match('/^container\./', $name)) {
return FALSE;
}
if (preg_match('/^drupal\./', $name)) {
return FALSE;
}
if (preg_match('/^console\./', $name)) {
return FALSE;
}
return TRUE;
}, ARRAY_FILTER_USE_KEY);

return $parameters;
}

}

0 comments on commit e4e6062

Please sign in to comment.