Skip to content

Commit

Permalink
Merge pull request #732 from KhorneHoly/main
Browse files Browse the repository at this point in the history
Deserializes.php broke if the type is an DateTimeInterface due to only checking for classes and not interfaces
  • Loading branch information
jlevers authored Jun 18, 2024
2 parents 496e7ed + a95c993 commit fa96840
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Traits/Deserializes.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ protected static function deserializeValue(mixed $value, array|string $type): mi
return $_value;
}

if (! class_exists($type)) {
throw new InvalidAttributeTypeException("Class `$type` does not exist");
} elseif ($type === DateTime::class) {
return DateTime::createFromFormat(static::$datetimeFormat, $value);
if (! class_exists($type) && ! interface_exists($type)) {
throw new InvalidAttributeTypeException("Neither the Class nor Interface `$type` exists");
} elseif ($type == \DateTimeInterface::class) {
if (strlen($value) === 10) {
return DateTime::createFromFormat('Y-m-d', $value);
} else {
return DateTime::createFromFormat(static::$datetimeFormat, $value);
}
}

$deserialized = $type::deserialize($value);
Expand Down

0 comments on commit fa96840

Please sign in to comment.