From d7c59ed48fbd6cface29f2476b35758403c8d62b Mon Sep 17 00:00:00 2001 From: Robert Lemke Date: Mon, 21 Mar 2022 18:41:22 +0100 Subject: [PATCH] Allow "static" return type for constructor methods The constructor methods for value objects (for example `fromArray()`) are considered by the `ValueObjectNormalizer` when events are unserialized from the event store. However, if a `fromArray()` method is declared with a `static` return type, the method is not considered by the normalizer. This change adds support for those constructors. --- Classes/EventStore/Normalizer/ValueObjectNormalizer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/EventStore/Normalizer/ValueObjectNormalizer.php b/Classes/EventStore/Normalizer/ValueObjectNormalizer.php index af52abeb..dc25f11b 100644 --- a/Classes/EventStore/Normalizer/ValueObjectNormalizer.php +++ b/Classes/EventStore/Normalizer/ValueObjectNormalizer.php @@ -15,7 +15,7 @@ * * they are public * * they are static * * they expect a single parameter of the given type - * * they have a "self" or "" return type annotation + * * they have a "self", "static" or "" return type annotation * * Note: For type "array" a named constructor fromArray() is required! */ @@ -116,7 +116,7 @@ private function resolveNamedConstructorMethod(string $dataType, string $classNa return null; } $constructorMethodReturnTypeName = $constructorMethodReturnType->getName(); - if ($constructorMethodReturnTypeName !== $className && $constructorMethodReturnTypeName !== 'self') { + if ($constructorMethodReturnTypeName !== $className && $constructorMethodReturnTypeName !== 'self' && $constructorMethodReturnTypeName !== 'static') { return null; } $this->resolveNamedConstructorMethodCache[$cacheIdentifier] = $constructorMethod;