Skip to content
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

feat: resolve extension parameters in compiler passes #3684

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Resolve extension parameters in Shopware compiler passes
issue:
flag:
author: Philip Standt
author_email: philip@maphi.net
author_github: @Ocarthon
---
# Core
* Changed `\Shopware\Core\Framework\DependencyInjection\CompilerPass\CompilerPassConfigTrait` to resolve extension parameters before processing the values.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ trait CompilerPassConfigTrait
*/
public function getConfig(ContainerBuilder $container, string $bundle): array
{
$config = $container->getExtensionConfig($bundle);

$resolvingBag = $container->getParameterBag();
$config = $resolvingBag->resolveValue($config);

return (new Processor())
->processConfiguration(
new Configuration($container->getParameter('kernel.debug')),
$container->getExtensionConfig($bundle)
$config,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php declare(strict_types=1);

namespace Shopware\Tests\Integration\Core\Framework\DependencyInjection\CompilerPass;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Framework\DependencyInjection\CompilerPass\CompilerPassConfigTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;

/**
* @internal
*/
#[CoversClass(CompilerPassConfigTraitTest::class)]
class CompilerPassConfigTraitTest extends TestCase
{
public function testAutoConfigure(): void
{
$parameterBag = new EnvPlaceholderParameterBag();
$container = new ContainerBuilder($parameterBag);
$container->setParameter('kernel.debug', true);

$container->registerExtension(new MockFrameworkExtension());
$container->prependExtensionConfig('framework', [
'http_cache' => [
'default_ttl' => '%env(int:DUMMY_ENV)%',
],
]);

$container->addCompilerPass(new ValidateEnvPlaceholdersPass());
$container->addCompilerPass(new ExampleCompilerPass());

$this->expectNotToPerformAssertions();
$container->compile(true);
}
}

/**
* @internal
*/
class ExampleCompilerPass implements CompilerPassInterface
{
use CompilerPassConfigTrait;

public function process(ContainerBuilder $container): void
{
$this->getConfig($container, 'framework');
}
}

/**
* @internal
*/
class MockFrameworkExtension implements ExtensionInterface
{
public function load(array $configs, ContainerBuilder $container): void
{
}

public function getNamespace(): string
{
return '';
}

public function getXsdValidationBasePath(): string|false
{
return false;
}

public function getAlias(): string
{
return 'framework';
}
}