99
1010class ObjectTypeMapper implements TypeMapper {
1111 public function __construct (
12- private JSONPlus $ jsonPlus
12+ private JSONPlus $ jsonPlus ,
13+ private EnumTypeMapper $ enumTypeMapper
1314 ){
1415 }
1516
@@ -18,6 +19,10 @@ public function map(mixed $o, string $type): mixed {
1819 return null ;
1920
2021 $ class = new ReflectionClass (str_replace ("? " , "" , $ type ));
22+ if ($ class ->isEnum ()) {
23+ return $ this ->enumTypeMapper ->map ($ class , $ o );
24+ }
25+
2126 $ oo = $ class ->newInstance ();
2227
2328 foreach ($ class ->getProperties () as $ property ) {
@@ -53,13 +58,19 @@ public function mapToJson(mixed $o, string $type): mixed {
5358 if ($ o === null )
5459 return null ;
5560 $ class = new ReflectionClass (str_replace ("? " , "" , $ type ));
61+
62+ if ($ class ->isEnum ()) {
63+ return $ this ->enumTypeMapper ->mapToJson ($ class , $ o );
64+ }
65+
5666 $ oo = [];
5767 foreach ($ class ->getProperties () as $ property ) {
5868 if (!$ property ->isStatic ()) {
5969 $ name = $ property ?->getName();
6070
6171 $ overrideName = $ property ?->getName();
6272 $ serializeAttribs = $ property ->getAttributes (Serialize::class);
73+
6374 foreach ($ serializeAttribs as $ attrib ) {
6475 $ attrib = $ attrib ->newInstance ();
6576 $ overrideName = $ attrib ->value ;
0 commit comments