@@ -76,11 +76,22 @@ public function map(string $class, bool $requireValues = false, ?array $source =
7676 * @return int|float|string|bool
7777 * The passed value, but now with the correct type.
7878 */
79- private function typeNormalize (string $ val , \ReflectionProperty $ rProp ): int |float |string |bool
79+ private function typeNormalize (string $ val , \ReflectionProperty $ rProp ): int |float |string |bool | \ BackedEnum
8080 {
8181 $ rType = $ rProp ->getType ();
8282 if ($ rType instanceof \ReflectionNamedType) {
83- return match ($ rType ->getName ()) {
83+ $ name = $ rType ->getName ();
84+
85+ if (is_a ($ name , \BackedEnum::class, true )) {
86+ $ rEnum = new \ReflectionEnum ($ name );
87+ $ backingType = $ rEnum ->getBackingType ();
88+ assert ($ backingType instanceof \ReflectionNamedType);
89+ $ isIntBacked = $ backingType ->getName () === 'int ' ;
90+
91+ return $ name ::from ($ isIntBacked ? (int ) $ val : $ val );
92+ }
93+
94+ return match ($ name ) {
8495 'string ' => $ val ,
8596 'float ' => is_numeric ($ val )
8697 ? (float ) $ val
@@ -118,6 +129,9 @@ protected function getDefaultValue(\ReflectionProperty $subject): mixed
118129 }
119130
120131 /**
132+ * @template T of object
133+ * @param \ReflectionClass<T> $rClass
134+ *
121135 * @return array<string, \ReflectionParameter>
122136 */
123137 protected function getConstructorArgs (\ReflectionClass $ rClass ): array
@@ -126,6 +140,9 @@ protected function getConstructorArgs(\ReflectionClass $rClass): array
126140 }
127141
128142 /**
143+ * @template T of object
144+ * @param \ReflectionClass<T> $rClass
145+ *
129146 * @return array<string, \ReflectionParameter>
130147 */
131148 protected function makeConstructorArgs (\ReflectionClass $ rClass ): array
0 commit comments