1
0
mirror of synced 2025-01-18 22:41:43 +03:00

Using instantiator to work with internal PHP classes as embeddables

This commit is contained in:
Marco Pivetta 2014-12-05 13:00:54 +01:00
parent a8b0ac82b4
commit 112fdf46d0

View File

@ -18,6 +18,8 @@
*/
namespace Doctrine\ORM\Mapping;
use Doctrine\Instantiator\Instantiator;
use ReflectionProperty;
/**
@ -46,6 +48,11 @@ class ReflectionEmbeddedProperty
*/
private $class;
/**
* @var Instantiator|null
*/
private $instantiator;
/**
* @param ReflectionProperty $parentProperty
* @param ReflectionProperty $childProperty
@ -83,7 +90,10 @@ class ReflectionEmbeddedProperty
$embeddedObject = $this->parentProperty->getValue($object);
if (null === $embeddedObject) {
$embeddedObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->class), $this->class));
$this->instantiator = $this->instantiator ?: new Instantiator();
$embeddedObject = $this->instantiator->instantiate($this->class);
$this->parentProperty->setValue($object, $embeddedObject);
}