You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -78,13 +104,48 @@ protected function finalizeValue(mixed $value): mixed
78
104
{
79
105
$value = parent::finalizeValue($value);
80
106
81
-
if (!\in_array($value, $this->values, true)) {
82
-
$ex = newInvalidConfigurationException(\sprintf('The value %s is not allowed for path "%s". Permissible values: %s', json_encode($value), $this->getPath(), $this->getPermissibleValues(', ')));
83
-
$ex->setPath($this->getPath());
107
+
if ($this->enumFqcn) {
108
+
if (is_a($this->enumFqcn, \BackedEnum::class, true)) {
109
+
if (\is_string($value) || \is_int($value)) {
110
+
try {
111
+
$case = $this->enumFqcn::tryFrom($value);
112
+
} catch (\TypeError) {
113
+
thrownewInvalidConfigurationException(\sprintf('The value could not be casted to a case of the "%s" enum. Is the value the same type as the backing type of the enum?', $this->enumFqcn));
thrownewInvalidConfigurationException(\sprintf('The value should be part of the "%s" enum, got a value from the "%s" enum.', $this->enumFqcn, get_debug_type($value)));
$message = \sprintf('The value %s is not allowed for path "%s". Permissible values: %s (cases of the "%s" enum).', json_encode($value), $this->getPath(), $this->getPermissibleValues(', '), $this->enumFqcn);
142
+
} else {
143
+
$message = \sprintf('The value %s is not allowed for path "%s". Permissible values: %s.', json_encode($value), $this->getPath(), $this->getPermissibleValues(', '));
Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php
+46
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,8 @@ class PrimitiveTypesConfig implements \Symfony\Component\Config\Builder\ConfigBu
12
12
{
13
13
private$booleanNode;
14
14
private$enumNode;
15
+
private$fqcnEnumNode;
16
+
private$fqcnUnitEnumNode;
15
17
private$floatNode;
16
18
private$integerNode;
17
19
private$scalarNode;
@@ -44,6 +46,32 @@ public function enumNode($value): static
Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php
+4
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,8 @@ private function getConfigurationAsString()
42
42
<!-- scalar-deprecated-with-message: Deprecated (Since vendor/package 1.1: Deprecation custom message for "scalar_deprecated_with_message" at "acme_root") -->
43
43
<!-- enum-with-default: One of "this"; "that" -->
44
44
<!-- enum: One of "this"; "that"; Symfony\Component\Config\Tests\Fixtures\TestEnum::Ccc -->
45
+
<!-- enum-with-class: One of foo; bar -->
46
+
<!-- unit-enum-with-class: One of Symfony\Component\Config\Tests\Fixtures\TestEnum::Foo; Symfony\Component\Config\Tests\Fixtures\TestEnum::Bar; Symfony\Component\Config\Tests\Fixtures\TestEnum::Ccc -->
45
47
<!-- variable: Example: foo, bar -->
46
48
<config
47
49
boolean="true"
@@ -58,6 +60,8 @@ private function getConfigurationAsString()
Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php
+2
Original file line number
Diff line number
Diff line change
@@ -103,6 +103,8 @@ private function getConfigurationAsString(): string
103
103
node_with_a_looong_name: ~
104
104
enum_with_default: this # One of "this"; "that"
105
105
enum: ~ # One of "this"; "that"; Symfony\Component\Config\Tests\Fixtures\TestEnum::Ccc
106
+
enum_with_class: ~ # One of foo; bar
107
+
unit_enum_with_class: ~ # One of Symfony\Component\Config\Tests\Fixtures\TestEnum::Foo; Symfony\Component\Config\Tests\Fixtures\TestEnum::Bar; Symfony\Component\Config\Tests\Fixtures\TestEnum::Ccc
0 commit comments