[Console] Add path argument to dump a specific option in debug:config
Handle failure on undefined path, Add tests PHPDoc fix Remove useless assertion
This commit is contained in:
parent
b59664bc42
commit
05ae01bf02
@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Console\Exception\LogicException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
@ -34,6 +35,7 @@ class ConfigDebugCommand extends AbstractConfigCommand
|
||||
->setName('debug:config')
|
||||
->setDefinition(array(
|
||||
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
|
||||
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
|
||||
))
|
||||
->setDescription('Dumps the current configuration for an extension')
|
||||
->setHelp(<<<EOF
|
||||
@ -60,6 +62,7 @@ EOF
|
||||
if (null === $name = $input->getArgument('name')) {
|
||||
$this->listBundles($io);
|
||||
$io->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. <comment>debug:config FrameworkBundle</comment>)');
|
||||
$io->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>debug:config FrameworkBundle serializer</comment> to dump the <comment>framework.serializer</comment> configuration)');
|
||||
|
||||
return;
|
||||
}
|
||||
@ -67,7 +70,8 @@ EOF
|
||||
$extension = $this->findExtension($name);
|
||||
$container = $this->compileContainer();
|
||||
|
||||
$configs = $container->getExtensionConfig($extension->getAlias());
|
||||
$extensionAlias = $extension->getAlias();
|
||||
$configs = $container->getExtensionConfig($extensionAlias);
|
||||
$configuration = $extension->getConfiguration($configs, $container);
|
||||
|
||||
$this->validateConfiguration($extension, $configuration);
|
||||
@ -77,13 +81,27 @@ EOF
|
||||
$processor = new Processor();
|
||||
$config = $processor->processConfiguration($configuration, $configs);
|
||||
|
||||
if ($name === $extension->getAlias()) {
|
||||
$io->title(sprintf('Current configuration for extension with alias "%s"', $name));
|
||||
} else {
|
||||
$io->title(sprintf('Current configuration for "%s"', $name));
|
||||
if (null === $path = $input->getArgument('path')) {
|
||||
$io->title(
|
||||
sprintf('Current configuration for %s', ($name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name)))
|
||||
);
|
||||
|
||||
$io->writeln(Yaml::dump(array($extensionAlias => $config), 10));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeln(Yaml::dump(array($extension->getAlias() => $config), 10));
|
||||
try {
|
||||
$config = $this->getConfigForPath($config, $path, $extensionAlias);
|
||||
} catch (LogicException $e) {
|
||||
$io->error($e->getMessage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->title(sprintf('Current configuration for "%s.%s"', $extensionAlias, $path));
|
||||
|
||||
$io->writeln(Yaml::dump($config, 10));
|
||||
}
|
||||
|
||||
private function compileContainer()
|
||||
@ -98,4 +116,28 @@ EOF
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over configuration until the last step of the given path.
|
||||
*
|
||||
* @param array $config A bundle configuration.
|
||||
*
|
||||
* @throws LogicException If the configuration does not exist
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getConfigForPath(array $config = array(), $path, $alias)
|
||||
{
|
||||
$steps = explode('.', $path);
|
||||
|
||||
foreach ($steps as $step) {
|
||||
if (!array_key_exists($step, $config)) {
|
||||
throw new LogicException(sprintf('Unable to find configuration for "%s.%s"', $alias, $path));
|
||||
}
|
||||
|
||||
$config = $config[$step];
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,23 @@ class ConfigDebugCommandTest extends WebTestCase
|
||||
$this->assertContains('custom: foo', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testDumpBundleOption()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$ret = $tester->execute(array('name' => 'TestBundle', 'path' => 'custom'));
|
||||
|
||||
$this->assertSame(0, $ret, 'Returns 0 in case of success');
|
||||
$this->assertContains('foo', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testDumpUndefinedBundleOption()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$ret = $tester->execute(array('name' => 'TestBundle', 'path' => 'foo'));
|
||||
|
||||
$this->assertContains('Unable to find configuration for "test.foo"', $tester->getDisplay());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CommandTester
|
||||
*/
|
||||
|
Reference in New Issue
Block a user