Skip to content

Commit d0d69cd

Browse files
author
jack.shpartko
committed
Bugfix: add \UnitEnum as a result of get() method
1 parent b45d86f commit d0d69cd

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EnvPlaceholderParameterBag extends ParameterBag
2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function get(string $name): array|bool|string|int|float|null
32+
public function get(string $name): array|bool|string|int|float|\UnitEnum|null
3333
{
3434
if (str_starts_with($name, 'env(') && str_ends_with($name, ')') && 'env()' !== $name) {
3535
$env = substr($name, 4, -1);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
enum StringBackedEnum: string
15+
{
16+
case Bar = 'bar';
17+
}

src/Symfony/Component/DependencyInjection/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1616
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1717
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
18+
use Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum;
1819

1920
class EnvPlaceholderParameterBagTest extends TestCase
2021
{
@@ -196,4 +197,12 @@ public function testExtraCharsInProcessor()
196197
$bag->resolve();
197198
$this->assertStringMatchesFormat('env_%s_key_a_b_c_FOO_%s', $bag->get('env(key:a.b-c:FOO)'));
198199
}
200+
201+
public function testGetEnum()
202+
{
203+
$bag = new EnvPlaceholderParameterBag();
204+
$bag->set('ENUM_VAR', StringBackedEnum::Bar);
205+
$this->assertInstanceOf(StringBackedEnum::class, $bag->get('ENUM_VAR'));
206+
$this->assertEquals(StringBackedEnum::Bar, $bag->get('ENUM_VAR'));
207+
}
199208
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy