From 5586ddd6b7cbd73659d93615d1a1db0bea8e7300 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Sat, 2 Nov 2013 13:27:17 +0100 Subject: [PATCH] removes restrictions on constructors of embedded objects --- .../ORM/Mapping/ReflectionEmbeddedProperty.php | 2 +- .../Tests/ORM/Functional/ValueObjectsTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php index b68d7d818..662c00690 100644 --- a/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php +++ b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php @@ -57,7 +57,7 @@ class ReflectionEmbeddedProperty $embeddedObject = $this->parentProperty->getValue($object); if ($embeddedObject === null) { - $embeddedObject = new $this->class; // TODO + $embeddedObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->class), $this->class)); $this->parentProperty->setValue($object, $embeddedObject); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index f82220a1f..03bab0843 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -176,10 +176,28 @@ class DDC93Person /** @Embedded(class="DDC93Address") */ public $address; + /** @Embedded(class = "DDC93Timestamps") */ + public $timestamps; + public function __construct($name = null, DDC93Address $address = null) { $this->name = $name; $this->address = $address; + $this->timestamps = new DDC93Timestamps(new \DateTime); + } +} + +/** + * @Embeddable + */ +class DDC93Timestamps +{ + /** @Column(type = "datetime") */ + public $createdAt; + + public function __construct(\DateTime $createdAt) + { + $this->createdAt = $createdAt; } }