Skip to content

Commit 75da869

Browse files
alamiraultnicolas-grekas
authored andcommitted
[DependencyInjection] Fix ContainerBuilder stats env usage with enum
1 parent 97f0ce8 commit 75da869

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function get(string $name): array|bool|string|int|float|\UnitEnum|null
4949
}
5050

5151
$uniqueName = md5($name.'_'.self::$counter++);
52-
$placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.', '___'), $uniqueName);
52+
$placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.\\', '____'), $uniqueName);
5353
$this->envPlaceholders[$env][$placeholder] = $placeholder;
5454

5555
return $placeholder;

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument;
5252
use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory;
5353
use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;
54+
use Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum;
5455
use Symfony\Component\DependencyInjection\Tests\Fixtures\WitherStaticReturnType;
5556
use Symfony\Component\DependencyInjection\TypedReference;
5657
use Symfony\Component\ExpressionLanguage\Expression;
@@ -545,6 +546,23 @@ public function testEnvExpressionFunction()
545546
$this->assertEquals('Foo value', $container->get('bar')->foo);
546547
}
547548

549+
public function testGetEnvCountersWithEnum()
550+
{
551+
$bag = new EnvPlaceholderParameterBag();
552+
$config = new ContainerBuilder($bag);
553+
$config->resolveEnvPlaceholders([
554+
$bag->get('env(enum:'.StringBackedEnum::class.':foo)'),
555+
$bag->get('env(Bar)'),
556+
]);
557+
558+
$expected = [
559+
'enum:Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum:foo' => 1,
560+
'Bar' => 1,
561+
];
562+
563+
$this->assertSame($expected, $config->getEnvCounters());
564+
}
565+
548566
public function testCreateServiceWithAbstractArgument()
549567
{
550568
$this->expectException(RuntimeException::class);

0 commit comments

Comments
 (0)