Using instantiator to work with internal PHP classes as embeddables
This commit is contained in:
parent
a8b0ac82b4
commit
112fdf46d0
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user