Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05ae01b

Browse files
committed
[Console] Add path argument to dump a specific option in debug:config
Handle failure on undefined path, Add testsPHPDoc fixRemove useless assertion
1 parentb59664b commit05ae01b

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
useSymfony\Component\Console\Input\InputInterface;
1717
useSymfony\Component\Console\Output\OutputInterface;
1818
useSymfony\Component\Console\Style\SymfonyStyle;
19+
useSymfony\Component\Console\Exception\LogicException;
1920
useSymfony\Component\Yaml\Yaml;
2021

2122
/**
@@ -34,6 +35,7 @@ protected function configure()
3435
->setName('debug:config')
3536
->setDefinition(array(
3637
newInputArgument('name', InputArgument::OPTIONAL,'The bundle name or the extension alias'),
38+
newInputArgument('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 =newProcessor();
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
privatefunctioncompileContainer()
@@ -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+
privatefunctiongetConfigForPath(array$config =array(),$path,$alias)
130+
{
131+
$steps =explode('.',$path);
132+
133+
foreach ($stepsas$step) {
134+
if (!array_key_exists($step,$config)) {
135+
thrownewLogicException(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+
publicfunctiontestDumpBundleOption()
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+
publicfunctiontestDumpUndefinedBundleOption()
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)

[8]ページ先頭

©2009-2025 Movatter.jp