Skip to content

Commit 05165bd

Browse files
authored
refactor(mapper): improve property and enum handling (#1773)
1 parent 9ad1587 commit 05165bd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

packages/mapper/src/Casters/EnumCaster.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function cast(mixed $input): ?object
3030
return constant("{$this->enum}::{$input}");
3131
}
3232

33+
if (! is_a($this->enum, \BackedEnum::class, allow_string: true)) {
34+
return null;
35+
}
36+
3337
return forward_static_call("{$this->enum}::from", $input);
3438
}
3539
}

packages/mapper/src/Mappers/ObjectToArrayMapper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public function map(mixed $from, mixed $to): mixed
4949

5050
private function resolvePropertyValue(PropertyReflector $property, object $object): mixed
5151
{
52+
if (! $property->isInitialized($object)) {
53+
return null;
54+
}
55+
5256
$propertyValue = $property->getValue($object);
5357

5458
if ($property->getIterableType()?->isClass()) {

0 commit comments

Comments
 (0)