Skip to content

Commit

Permalink
Updated patch with fixes for bugs found during running the whole doct…
Browse files Browse the repository at this point in the history
…rine test suite, updated docs
  • Loading branch information
sspat committed Dec 4, 2019
1 parent 9114fa7 commit c56f1ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ using https://github.com/cweagans/composer-patches.

You can review the contents of this patch in `patch/nullable_embeddables.patch`

It works by analyzing the types of the properties of the entity and the value-object.
If the entity property containing the value-object is declared as nullable and
none of the value-object's properties that are not declared nullable get null values from the
database - then the entity property will be hydrated with the value object.
All other cases are considered an invalid state based on the provided typing and will result in
hydrating to null on the corresponding property of the entity.

The tradeoffs of this approach will be:
- You can't update Doctrine directly, only update it with this package
- You will need PHP 7.4
Expand Down
16 changes: 11 additions & 5 deletions patch/nullable_embeddables.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
diff --git a/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php
index b224fff4e..67d5e1da4 100644
index b224fff4e..13404d91a 100644
--- a/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php
+++ b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php
@@ -72,13 +72,13 @@ class ReflectionEmbeddedProperty extends ReflectionProperty
@@ -72,13 +72,16 @@ class ReflectionEmbeddedProperty extends ReflectionProperty
*/
public function getValue($object = null)
{
- $embeddedObject = $this->parentProperty->getValue($object);
+ $embeddedObject = $this->parentProperty->isInitialized($object) ? $this->parentProperty->getValue($object) : null;
+ $embeddedObject = ! $this->parentProperty->getDeclaringClass()->isInstance($object) ||
+ $this->parentProperty->isInitialized($object) ?
+ $this->parentProperty->getValue($object) :
+ null;

if (null === $embeddedObject) {
return null;
Expand All @@ -18,7 +21,7 @@ index b224fff4e..67d5e1da4 100644
}

/**
@@ -86,7 +86,18 @@ class ReflectionEmbeddedProperty extends ReflectionProperty
@@ -86,7 +89,21 @@ class ReflectionEmbeddedProperty extends ReflectionProperty
*/
public function setValue($object, $value = null)
{
Expand All @@ -34,7 +37,10 @@ index b224fff4e..67d5e1da4 100644
+ return;
+ }
+
+ $embeddedObject = $this->parentProperty->isInitialized($object) ? $this->parentProperty->getValue($object) : null;
+ $embeddedObject = ! $this->parentProperty->getDeclaringClass()->isInstance($object) ||
+ $this->parentProperty->isInitialized($object) ?
+ $this->parentProperty->getValue($object) :
+ null;

if (null === $embeddedObject) {
$this->instantiator = $this->instantiator ?: new Instantiator();

0 comments on commit c56f1ec

Please sign in to comment.