Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7dbcc9

Browse files
committed
feature #45624 [Config] Allow using environment variables in EnumNode (ecourtial)
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [Config] Allow using environment variables in `EnumNode` | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | In the _EnumNode_ of the _Config_ component, we see that it does not allow the use of a placeholder: https://github.com/symfony/symfony/blob/5fbd0dc062443d1c5050081a7eba23ef47ba2a25/src/Symfony/Component/Config/Definition/EnumNode.php#L63 This is strange, because we could have some use cases where we would like to be able to define the value with a env variable. A good example is the samesite policy for the session cookie : https://symfony.com/blog/new-in-symfony-4-2-samesite-cookie-configuration. Note: I have not submitted any documentation update so far, I am not even sure it is a "new" feature. Commits ------- 726bc28 [Config] Allow using environment variables in `EnumNode`
2 parents 2ac4503 + 726bc28 commit c7dbcc9

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Allow using environment variables in `EnumNode`
8+
49
6.0
510
---
611

src/Symfony/Component/Config/Definition/EnumNode.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,4 @@ protected function finalizeValue(mixed $value): mixed
5454

5555
return $value;
5656
}
57-
58-
/**
59-
* {@inheritdoc}
60-
*/
61-
protected function allowPlaceholders(): bool
62-
{
63-
return false;
64-
}
6557
}

src/Symfony/Component/Config/Tests/Definition/EnumNodeTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,20 @@ public function testFinalizeWithInvalidValue()
5555
$node = new EnumNode('foo', null, ['foo', 'bar']);
5656
$node->finalize('foobar');
5757
}
58+
59+
public function testWithPlaceHolderWithValidValue()
60+
{
61+
$node = new EnumNode('cookie_samesite', null, ['lax', 'strict', 'none']);
62+
EnumNode::setPlaceholder('custom', ['string' => 'lax']);
63+
$this->assertSame('custom', $node->finalize('custom'));
64+
}
65+
66+
public function testWithPlaceHolderWithInvalidValue()
67+
{
68+
$node = new EnumNode('cookie_samesite', null, ['lax', 'strict', 'none']);
69+
EnumNode::setPlaceholder('custom', ['string' => 'foo']);
70+
$this->expectException(InvalidConfigurationException::class);
71+
$this->expectExceptionMessage('The value "foo" is not allowed for path "cookie_samesite". Permissible values: "lax", "strict", "none"');
72+
$node->finalize('custom');
73+
}
5874
}

0 commit comments

Comments
 (0)