Skip to content

Commit

Permalink
NEXT-36143 - feat: resolve extension parameters in compiler passes
Browse files Browse the repository at this point in the history
fixes #3684
  • Loading branch information
Ocarthon authored and AydinHassan committed May 14, 2024
1 parent 8688475 commit dfd0990
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Resolve extension parameters in Shopware compiler passes
issue: NEXT-36143
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';
}
}

0 comments on commit dfd0990

Please sign in to comment.