From be54586c5c542dfedf1d1e16a331cd5858ada797 Mon Sep 17 00:00:00 2001 From: Jelmer Prins Date: Thu, 14 Nov 2019 08:34:07 +0100 Subject: [PATCH] DBAL Types always need to know how to handle null This is because queries that don't filter on the dbal type will have null as value --- .../Domain/MyTestEntity/MyValueObjectDBALType.php | 6 +++++- .../resources/php71/Standalone/MyValueObjectDBALType.php | 6 +++++- src/Domain/ValueObject/ValueObjectDBALType.php71.php.twig | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/features/generate/domain/resources/php71/Backend/Modules/TestModule/Domain/MyTestEntity/MyValueObjectDBALType.php b/features/generate/domain/resources/php71/Backend/Modules/TestModule/Domain/MyTestEntity/MyValueObjectDBALType.php index 3e702df..9a8a59c 100644 --- a/features/generate/domain/resources/php71/Backend/Modules/TestModule/Domain/MyTestEntity/MyValueObjectDBALType.php +++ b/features/generate/domain/resources/php71/Backend/Modules/TestModule/Domain/MyTestEntity/MyValueObjectDBALType.php @@ -12,8 +12,12 @@ public function getName(): string return 'testmodule_mytestentity_myvalueobject'; } - public function convertToPHPValue($myValueObjectDBALType, AbstractPlatform $platform): MyValueObject + public function convertToPHPValue($myValueObjectDBALType, AbstractPlatform $platform): ?MyValueObject { + if ($myValueObjectDBALType === null) { + return null; + } + return new MyValueObject($myValueObjectDBALType); } diff --git a/features/generate/domain/resources/php71/Standalone/MyValueObjectDBALType.php b/features/generate/domain/resources/php71/Standalone/MyValueObjectDBALType.php index 40f9d01..ad9e6a0 100644 --- a/features/generate/domain/resources/php71/Standalone/MyValueObjectDBALType.php +++ b/features/generate/domain/resources/php71/Standalone/MyValueObjectDBALType.php @@ -12,8 +12,12 @@ public function getName(): string return 'myvalueobject'; } - public function convertToPHPValue($myValueObjectDBALType, AbstractPlatform $platform): MyValueObject + public function convertToPHPValue($myValueObjectDBALType, AbstractPlatform $platform): ?MyValueObject { + if ($myValueObjectDBALType === null) { + return null; + } + return new MyValueObject($myValueObjectDBALType); } diff --git a/src/Domain/ValueObject/ValueObjectDBALType.php71.php.twig b/src/Domain/ValueObject/ValueObjectDBALType.php71.php.twig index 97a4dbc..db97acb 100644 --- a/src/Domain/ValueObject/ValueObjectDBALType.php71.php.twig +++ b/src/Domain/ValueObject/ValueObjectDBALType.php71.php.twig @@ -12,8 +12,12 @@ final class {{ class.className.name }} extends StringType return '{{ class.name }}'; } - public function convertToPHPValue(${{ class.className.forParameter }}, AbstractPlatform $platform): {{ class.valueObjectClassName.name }} + public function convertToPHPValue(${{ class.className.forParameter }}, AbstractPlatform $platform): ?{{ class.valueObjectClassName.name }} { + if (${{ class.className.forParameter }} === null) { + return null; + } + return new {{ class.valueObjectClassName.name }}(${{ class.className.forParameter }}); }