Skip to content

Commit

Permalink
Allow "static" return type for constructor methods
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robertlemke authored Mar 21, 2022
1 parent 0743f57 commit d7c59ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Classes/EventStore/Normalizer/ValueObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* * they are public
* * they are static
* * they expect a single parameter of the given type
* * they have a "self" or "<TargetClassName>" return type annotation
* * they have a "self", "static" or "<TargetClassName>" return type annotation
*
* Note: For type "array" a named constructor fromArray() is required!
*/
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d7c59ed

Please sign in to comment.