8000 feature #18940 [Console] Add path argument to dump a specific option … · symfony/symfony@030abb2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 030abb2

Browse files
committed
feature #18940 [Console] Add path argument to dump a specific option in debug:config (chalasr)
This PR was merged into the 3.2-dev branch. Discussion ---------- [Console] Add path argument to dump a specific option in debug:config | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This adds the ability to dump a specific bundle config option from the `debug:config` command. For instance `debug:config StofDoctrineExtensionsBundle uploadable` gives: ![](http://image.prntscr.com/image/b78953dbe34c4efd817bb6f831ddd0ba.png) I hesitated to just look for a `.` in the `name` argument rather than adding a `path` argument that doesn't include the bundle alias (that is took from the first argument of the command), let me know what you think about that. Commits ------- 05ae01b [Console] Add path argument to dump a specific option in debug:config
2 parents ee68887 + 05ae01b commit 030abb2

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
1818
use Symfony\Component\Console\Style\SymfonyStyle;
19+
use Symfony\Component\Console\Exception\LogicException;
1920
use Symfony\Component\Yaml\Yaml;
2021

2122
/**
@@ -34,6 +35,7 @@ protected function configure()
3435
->setName('debug:config')
3536
->setDefinition(array(
3637
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
38+
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
3739
))
3840
->setDescription('Dumps the current configuration for an extension')
3941
->setHelp(<<<EOF
@@ -60,14 +62,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
6062
if (null === $name = $input->getArgument('name')) {
6163
$this->listBundles($io);
6264
$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>)');
65+
$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)');
6366

6467
return;
6568
}
6669

6770
$extension = $this->findExtension($name);
6871
$container = $this->compileContainer();
6972

70-
$configs = $container->getExtensionConfig($extension->getAlias());
73+
$extensionAlias = $extension->getAlias();
74+
$configs = $container->getExtensionConfig($extensionAlias);
7175
$configuration = $extension->getConfiguration($configs, $container);
7276

7377
$this->validateConfiguration($extension, $configuration);
@@ -77,13 +81,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
7781
$processor = new Processor();
7882
$config = $processor->processConfiguration($configuration, $configs);
7983

80-
if ($name === $extension->getAlias()) {
81-
$io->title(sprintf('Current configuration for extension with alias "%s"', $name));
82-
} else {
83-
$io->title(sprintf('Current configuration for "%s"', $name));
84+
if (null === $path = $input->getArgument('path')) {
85+
$io->title(
86+
sprintf('Current configuration for %s', ($name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name)))
87+
);
88+
89+
$io->writeln(Yaml::dump(array($extensionAlias => $config), 10));
90+
91+
return;
8492
}
8593

86-
$io->writeln(Yaml::dump(array($extension->getAlias() => $config), 10));
94+
try {
95+
$config = $this->getConfigForPath($config, $path, $extensionAlias);
96+
} catch (LogicException $e) {
97+
$io->error($e->getMessage());
98+
99+
return;
100+
}
101+
102+
$io->title(sprintf('Current configuration for "%s.%s"', $extensionAlias, $path));
103+
104+
$io->writeln(Yaml::dump($config, 10));
87105
}
88106

89107
private function compileContainer()
@@ -98,4 +116,28 @@ private function compileContainer()
98116

99117
return $container;
100118
}
119+
120+
/**
121+
* Iterate over configuration until the last step of the given path.
122+
*
123+
* @param array $config A bundle configuration.
124+
*
125+
* @throws LogicException If the configuration does not exist
126+
*
127+
* @return mixed
128+
*/
129+
private function getConfigForPath(array $config = array(), $path, $alias)
130+
{
131+
$steps = explode('.', $path);
132+
133+
foreach ($steps as $step) {
134+
if (!array_key_exists($step, $config)) {
135+
throw new LogicException(sprintf('Unable to find configuration for "%s.%s"', $alias, $path));
136+
}
137+
138+
$config = $config[$step];
139+
}
140+
141+
return $config;
142+
}
101143
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ public function testDumpBundleName()
3939
$this->assertContains('custom: foo', $tester->getDisplay());
4040
}
4141

42+
public function testDumpBundleOption()
43+
{
44+
$tester = $this->createCommandTester();
45+
$ret = $tester->execute(array('name' => 'TestBundle', 'path' => 'custom'));
46+
47+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
48+
$this->assertContains('foo', $tester->getDisplay());
49+
}
50+
51+
public function testDumpUndefinedBundleOption()
52+
{
53+
$tester = $this->createCommandTester();
54+
$ret = $tester->execute(array('name' => 'TestBundle', 'path' => 'foo'));
55+
56+
$this->assertContains('Unable to find configuration for "test.foo"', $tester->getDisplay());
57+
}
58+
4259
/**
4360
* @return CommandTester
4461
*/

0 commit comments

Comments
 (0)
0