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

Skip to content

[Config] Add command to dump ConfigBuilders #40803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Command;

use Symfony\Component\Config\Builder\ConfigBuilderGeneratorInterface;
use Symfony\Component\Config\Definition\ConfigurationInterface;
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\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

/**
* A command for dumping all config builder for your bundles.
*
* @author Tobias Nyholm <[email protected]>
*
* @final
*/
class ConfigDumpBuilderCommand extends AbstractConfigCommand
{
protected static $defaultName = 'config:dump-builders';
protected static $defaultDescription = 'Dump the config builder for an extension';

private $generator;

public function __construct(ConfigBuilderGeneratorInterface $generator)
{
$this->generator = $generator;
parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setDefinition([
new InputArgument('name', InputArgument::OPTIONAL, 'The Bundle name or the extension alias'),
])
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command dumps "configuration bundles" that help
writing configuration for an extension/bundle.

Either the extension alias or bundle name can be used:

<info>php %command.full_name% framework</info>
<info>php %command.full_name% FrameworkBundle</info>

EOF
)
;
}

/**
* {@inheritdoc}
*
* @throws \LogicException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$errorIo = $io->getErrorStyle();

if (null !== $name = $input->getArgument('name')) {
$extensions = [$this->findExtension($name)];
} else {
$extensions = array_map(function (BundleInterface $a) {
return $a->getContainerExtension();
}, $this->getApplication()->getKernel()->getBundles());
}

foreach ($extensions as $extension) {
if (null === $extension) {
continue;
}

try {
$this->dumpExtension($extension);
} catch (\Throwable $e) {
$errorIo->error(sprintf('Could not dump configuration for "%s". Exception: %s', \get_class($extension), $e->getMessage()));
}
}

return 0;
}

private function dumpExtension(ExtensionInterface $extension): void
{
if ($extension instanceof ConfigurationInterface) {
$configuration = $extension;
} else {
$configuration = $extension->getConfiguration([], $this->getContainerBuilder());
}

$this->generator->build($configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerAnnotationsConfiguration($config['annotations'], $container, $loader);
$this->registerPropertyAccessConfiguration($config['property_access'], $container, $loader);
$this->registerSecretsConfiguration($config['secrets'], $container, $loader);
$loader->load('config.php');

if ($this->isConfigEnabled($container, $config['serializer'])) {
if (!class_exists(\Symfony\Component\Serializer\Serializer::class)) {
Expand Down
25 changes: 25 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
use Symfony\Component\Config\Builder\ConfigBuilderGeneratorInterface;

return static function (ContainerConfigurator $container) {
$container->services()
->set('config.builder_generator', ConfigBuilderGenerator::class)
->args([
param('kernel.build_dir'),
])
->alias(ConfigBuilderGeneratorInterface::class, 'config.builder_generator')
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Bundle\FrameworkBundle\Command\CachePoolPruneCommand;
use Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand;
use Symfony\Bundle\FrameworkBundle\Command\ConfigDebugCommand;
use Symfony\Bundle\FrameworkBundle\Command\ConfigDumpBuilderCommand;
use Symfony\Bundle\FrameworkBundle\Command\ConfigDumpReferenceCommand;
use Symfony\Bundle\FrameworkBundle\Command\ContainerDebugCommand;
use Symfony\Bundle\FrameworkBundle\Command\ContainerLintCommand;
Expand All @@ -38,6 +39,7 @@
use Symfony\Bundle\FrameworkBundle\Command\WorkflowDumpCommand;
use Symfony\Bundle\FrameworkBundle\Command\YamlLintCommand;
use Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber;
use Symfony\Component\Config\Builder\ConfigBuilderGeneratorInterface;
use Symfony\Component\Console\EventListener\ErrorListener;
use Symfony\Component\Messenger\Command\ConsumeMessagesCommand;
use Symfony\Component\Messenger\Command\DebugCommand;
Expand Down Expand Up @@ -111,6 +113,12 @@
->set('console.command.config_debug', ConfigDebugCommand::class)
->tag('console.command')

->set('console.command.config_dump_builder', ConfigDumpBuilderCommand::class)
->args([
service(ConfigBuilderGeneratorInterface::class),
])
->tag('console.command')

->set('console.command.config_dump_reference', ConfigDumpReferenceCommand::class)
->tag('console.command')

Expand Down