Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec518e1

Browse files
committed
Adding command to dump builders
1 parent dd919a7 commit ec518e1

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Command;
13+
14+
use Symfony\Component\Config\Builder\ConfigBuilderGeneratorInterface;
15+
use Symfony\Component\Config\Definition\ConfigurationInterface;
16+
use Symfony\Component\Console\Input\InputArgument;
17+
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
20+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
21+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
22+
23+
/**
24+
* A command for dumping all config builder for your bundles.
25+
*
26+
* @author Tobias Nyholm <[email protected]>
27+
*
28+
* @final
29+
*/
30+
class ConfigDumpBuilderCommand extends AbstractConfigCommand
31+
{
32+
protected static $defaultName = 'config:dump-builders';
33+
protected static $defaultDescription = 'Dump the config builder for an extension';
34+
35+
private $generator;
36+
37+
public function __construct(ConfigBuilderGeneratorInterface $generator)
38+
{
39+
$this->generator = $generator;
40+
parent::__construct();
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
protected function configure()
47+
{
48+
$this
49+
->setDefinition([
50+
new InputArgument('name', InputArgument::OPTIONAL, 'The Bundle name or the extension alias'),
51+
])
52+
->setDescription(self::$defaultDescription)
53+
->setHelp(<<<'EOF'
54+
The <info>%command.name%</info> command dumps "configuration bundles" that help
55+
writing configuration for an extension/bundle.
56+
57+
Either the extension alias or bundle name can be used:
58+
59+
<info>php %command.full_name% framework</info>
60+
<info>php %command.full_name% FrameworkBundle</info>
61+
62+
EOF
63+
)
64+
;
65+
}
66+
67+
/**
68+
* {@inheritdoc}
69+
*
70+
* @throws \LogicException
71+
*/
72+
protected function execute(InputInterface $input, OutputInterface $output): int
73+
{
74+
$io = new SymfonyStyle($input, $output);
75+
$errorIo = $io->getErrorStyle();
76+
77+
if (null !== $name = $input->getArgument('name')) {
78+
$extensions = [$this->findExtension($name)];
79+
} else {
80+
$extensions = array_map(function (BundleInterface $a) {
81+
return $a->getContainerExtension();
82+
}, $this->getApplication()->getKernel()->getBundles());
83+
}
84+
85+
foreach ($extensions as $extension) {
86+
if (null === $extension) {
87+
continue;
88+
}
89+
90+
try {
91+
$this->dumpExtension($extension);
92+
} catch (\Throwable $e) {
93+
$errorIo->error(sprintf('Could not dump configuration for "%s". Exception: %s', \get_class($extension), $e->getMessage()));
94+
}
95+
}
96+
97+
return 0;
98+
}
99+
100+
private function dumpExtension(ExtensionInterface $extension): void
101+
{
102+
if ($extension instanceof ConfigurationInterface) {
103+
$configuration = $extension;
104+
} else {
105+
$configuration = $extension->getConfiguration([], $this->getContainerBuilder());
106+
}
107+
108+
$this->generator->build($configuration);
109+
}
110+
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ public function load(array $configs, ContainerBuilder $container)
425425
$this->registerAnnotationsConfiguration($config['annotations'], $container, $loader);
426426
$this->registerPropertyAccessConfiguration($config['property_access'], $container, $loader);
427427
$this->registerSecretsConfiguration($config['secrets'], $container, $loader);
428+
$loader->load('config.php');
428429

429430
if ($this->isConfigEnabled($container, $config['serializer'])) {
430431
if (!class_exists(\Symfony\Component\Serializer\Serializer::class)) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
15+
use Symfony\Component\Config\Builder\ConfigBuilderGeneratorInterface;
16+
17+
return static function (ContainerConfigurator $container) {
18+
$container->services()
19+
->set('config.builder_generator', ConfigBuilderGenerator::class)
20+
->args([
21+
param('kernel.build_dir'),
22+
])
23+
->alias(ConfigBuilderGeneratorInterface::class, 'config.builder_generator')
24+
;
25+
};

src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Bundle\FrameworkBundle\Command\CachePoolPruneCommand;
2121
use Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand;
2222
use Symfony\Bundle\FrameworkBundle\Command\ConfigDebugCommand;
23+
use Symfony\Bundle\FrameworkBundle\Command\ConfigDumpBuilderCommand;
2324
use Symfony\Bundle\FrameworkBundle\Command\ConfigDumpReferenceCommand;
2425
use Symfony\Bundle\FrameworkBundle\Command\ContainerDebugCommand;
2526
use Symfony\Bundle\FrameworkBundle\Command\ContainerLintCommand;
@@ -38,6 +39,7 @@
3839
use Symfony\Bundle\FrameworkBundle\Command\WorkflowDumpCommand;
3940
use Symfony\Bundle\FrameworkBundle\Command\YamlLintCommand;
4041
use Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber;
42+
use Symfony\Component\Config\Builder\ConfigBuilderGeneratorInterface;
4143
use Symfony\Component\Console\EventListener\ErrorListener;
4244
use Symfony\Component\Messenger\Command\ConsumeMessagesCommand;
4345
use Symfony\Component\Messenger\Command\DebugCommand;
@@ -111,6 +113,12 @@
111113
->set('console.command.config_debug', ConfigDebugCommand::class)
112114
->tag('console.command')
113115

116+
->set('console.command.config_dump_builder', ConfigDumpBuilderCommand::class)
117+
->args([
118+
service(ConfigBuilderGeneratorInterface::class),
119+
])
120+
->tag('console.command')
121+
114122
->set('console.command.config_dump_reference', ConfigDumpReferenceCommand::class)
115123
->tag('console.command')
116124

0 commit comments

Comments
 (0)