From 947d2e465476e10c3d2019ac6cc5b6c821708a1b Mon Sep 17 00:00:00 2001 From: oliver Date: Thu, 13 Jun 2024 15:46:10 +0200 Subject: [PATCH 1/3] Deserializes.php only checked for the DateTime class and not for the DateTimeInterface, so that the serialization process triggered an exception. --- src/Traits/Deserializes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Traits/Deserializes.php b/src/Traits/Deserializes.php index e62bf1533..5e2202504 100644 --- a/src/Traits/Deserializes.php +++ b/src/Traits/Deserializes.php @@ -79,9 +79,9 @@ protected static function deserializeValue(mixed $value, array|string $type): mi return $_value; } - if (! class_exists($type)) { + if (! class_exists($type) && ! interface_exists($type)) { throw new InvalidAttributeTypeException("Class `$type` does not exist"); - } elseif ($type === DateTime::class) { + } elseif ($type === DateTime::class || $type == \DateTimeInterface::class) { return DateTime::createFromFormat(DateTime::RFC3339, $value); } From 029cfb23da76079c81661f4708f500c867986686 Mon Sep 17 00:00:00 2001 From: oliver Date: Fri, 14 Jun 2024 12:52:15 +0200 Subject: [PATCH 2/3] Fix for Y-m-d date format. --- src/Traits/Deserializes.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Traits/Deserializes.php b/src/Traits/Deserializes.php index 5e2202504..d819199ec 100644 --- a/src/Traits/Deserializes.php +++ b/src/Traits/Deserializes.php @@ -82,7 +82,11 @@ protected static function deserializeValue(mixed $value, array|string $type): mi if (! class_exists($type) && ! interface_exists($type)) { throw new InvalidAttributeTypeException("Class `$type` does not exist"); } elseif ($type === DateTime::class || $type == \DateTimeInterface::class) { - return DateTime::createFromFormat(DateTime::RFC3339, $value); + if (strlen($value) === 10) { + return DateTime::createFromFormat('Y-m-d', $value); + } else { + return DateTime::createFromFormat(DateTime::RFC3339, $value); + } } $deserialized = $type::deserialize($value); From f918ef155eff4bb42d625d007b9a39155a16980b Mon Sep 17 00:00:00 2001 From: oliver Date: Tue, 18 Jun 2024 09:33:43 +0200 Subject: [PATCH 3/3] Updated code based on review --- src/Traits/Deserializes.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Traits/Deserializes.php b/src/Traits/Deserializes.php index d819199ec..9f4f1c63c 100644 --- a/src/Traits/Deserializes.php +++ b/src/Traits/Deserializes.php @@ -80,12 +80,12 @@ protected static function deserializeValue(mixed $value, array|string $type): mi } if (! class_exists($type) && ! interface_exists($type)) { - throw new InvalidAttributeTypeException("Class `$type` does not exist"); - } elseif ($type === DateTime::class || $type == \DateTimeInterface::class) { + 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(DateTime::RFC3339, $value); + return DateTime::createFromFormat('Y-m-d\TH:i:sZ', $value); } }