8000 [FrameworkBundle] Fix dumping extension config without bundle by yceruto · Pull Request #46412 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Fix dumping extension config without bundle #46412

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

Merged
merged 1 commit into from
May 21, 2022
Merged
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
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\StyleInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;

/**
Expand Down Expand Up @@ -59,7 +60,7 @@ protected function listBundles($output)
/**
* @return ExtensionInterface
*/
protected function findExtension($name)
protected function findExtension($name, ContainerBuilder $container)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a BC break

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad!

I don't remember, is it ok to add a new deprecation in a patch version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot do that in a patch release.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #46434

{
$bundles = $this->initializeBundles();
$minScore = \INF;
Expand All @@ -79,20 +80,18 @@ protected function findExtension($name)
$guess = $bundle->getName();
$minScore = $distance;
}
}

$extension = $bundle->getContainerExtension();

if ($extension) {
if ($name === $extension->getAlias()) {
return $extension;
}
if ($container->hasExtension($name)) {
return $container->getExtension($name);
}

$distance = levenshtein($name, $extension->getAlias());
foreach ($container->getExtensions() as $extension) {
$distance = levenshtein($name, $extension->getAlias());

if ($distance < $minScore) {
$guess = $extension->getAlias();
$minScore = $distance;
}
if ($distance < $minScore) {
$guess = $extension->getAlias();
$minScore = $distance;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

$extension = $this->findExtension($name);
$extensionAlias = $extension->getAlias();
$container = $this->compileContainer();
$extension = $this->findExtension($name, $container);
$extensionAlias = $extension->getAlias();

$config = $container->resolveEnvPlaceholders(
$container->getParameterBag()->resolveValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

$extension = $this->findExtension($name);
$container = $this->getContainerBuilder();
$extension = $this->findExtension($name, $container);

$configuration = $extension->getConfiguration([], $this->getContainerBuilder());
$configuration = $extension->getConfiguration([], $container);

$this->validateConfiguration($extension, $configuration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public function testDefaultParameterValueIsResolvedIfConfigIsExisting()
$this->assertStringContainsString(sprintf("dsn: 'file:%s/profiler'", $kernelCacheDir), $tester->getDisplay());
}

public function testDumpExtensionConfigWithoutBundle()
{
$tester = $this->createCommandTester();
$ret = $tester->execute(['name' => 'test_dump']);

$this->assertSame(0, $ret, 'Returns 0 in case of success');
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
}

public function testDumpUndefinedBundleOption()
{
$tester = $this->createCommandTester();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public function testDumpBundleName()
$this->assertStringContainsString(' custom:', $tester->getDisplay());
}

public function testDumpExtensionConfigWithoutBundle()
{
$tester = $this->createCommandTester();
$ret = $tester->execute(['name' => 'test_dump']);

$this->assertSame(0, $ret, 'Returns 0 in case of success');
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
}

public function testDumpAtPath()
{
$tester = $this->createCommandTester();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

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

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Extension;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;

class TestDumpExtension extends Extension implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('test_dump');
$treeBuilder->getRootNode()
->children()
->booleanNode('enabled')->defaultTrue()->end()
->end()
;

return $treeBuilder;
}

public function load(array $configs, ContainerBuilder $container)
{
}

public function getConfiguration(array $config, ContainerBuilder $container)
{
return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app;

use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Extension\TestDumpExtension;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -78,6 +79,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
protected function build(ContainerBuilder $container)
{
$container->register('logger', NullLogger::class);
$container->registerExtension(new TestDumpExtension());
}

public function __sleep(): array
Expand Down
0