Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ee94cc9

Browse filesBrowse files
bug #48502 [DependencyInjection] Fix ContainerBuilder stats env usage with enum (alamirault)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [DependencyInjection] Fix `ContainerBuilder` stats env usage with enum | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #48498 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Without patch: ```php [ 'enum:Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum:foo' => 0, 'Bar' => 1, ] ``` With patch: ```php [ 'enum:Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum:foo' => 1, 'Bar' => 1, ] ``` Commits ------- 75da869 [DependencyInjection] Fix `ContainerBuilder` stats env usage with enum
2 parents 7d45767 + 75da869 commit ee94cc9
Copy full SHA for ee94cc9

File tree

2 files changed

+19
-1
lines changed
Filter options

2 files changed

+19
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
+18Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.