diff --git a/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php index 0163ebb89..b224fff4e 100644 --- a/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php +++ b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php @@ -34,15 +34,20 @@ use ReflectionProperty; class ReflectionEmbeddedProperty extends ReflectionProperty { /** - * @var ReflectionProperty + * @var ReflectionProperty reflection property of the class where the embedded object has to be put */ private $parentProperty; /** - * @var ReflectionProperty + * @var ReflectionProperty reflection property of the embedded object */ private $childProperty; + /** + * @var string name of the embedded class to be eventually instantiated + */ + private $embeddedClass; + /** * @var Instantiator|null */ @@ -51,12 +56,13 @@ class ReflectionEmbeddedProperty extends ReflectionProperty /** * @param ReflectionProperty $parentProperty * @param ReflectionProperty $childProperty - * @param string $class + * @param string $embeddedClass */ - public function __construct(ReflectionProperty $parentProperty, ReflectionProperty $childProperty, $class) + public function __construct(ReflectionProperty $parentProperty, ReflectionProperty $childProperty, $embeddedClass) { - $this->parentProperty = $parentProperty; - $this->childProperty = $childProperty; + $this->parentProperty = $parentProperty; + $this->childProperty = $childProperty; + $this->embeddedClass = (string) $embeddedClass; parent::__construct($childProperty->getDeclaringClass()->getName(), $childProperty->getName()); } @@ -85,7 +91,7 @@ class ReflectionEmbeddedProperty extends ReflectionProperty if (null === $embeddedObject) { $this->instantiator = $this->instantiator ?: new Instantiator(); - $embeddedObject = $this->instantiator->instantiate($this->class); + $embeddedObject = $this->instantiator->instantiate($this->embeddedClass); $this->parentProperty->setValue($object, $embeddedObject); } diff --git a/tests/Doctrine/Tests/Models/Reflection/AbstractEmbeddable.php b/tests/Doctrine/Tests/Models/Reflection/AbstractEmbeddable.php new file mode 100644 index 000000000..2fecb4613 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Reflection/AbstractEmbeddable.php @@ -0,0 +1,11 @@ +getDeclaringClass()->getName() - ); + $embeddedPropertyReflection = new ReflectionEmbeddedProperty($parentProperty, $childProperty, $embeddableClass); $instantiator = new Instantiator(); @@ -43,21 +42,18 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase } /** - * @param ReflectionProperty $parentProperty - * @param ReflectionProperty $childProperty + * @param ReflectionProperty $parentProperty property of the embeddable/entity where to write the embeddable to + * @param ReflectionProperty $childProperty property of the embeddable class where to write values to + * @param string $embeddableClass name of the embeddable class to be instantiated * * @dataProvider getTestedReflectionProperties */ public function testWillSkipReadingPropertiesFromNullEmbeddable( ReflectionProperty $parentProperty, - ReflectionProperty $childProperty - ) - { - $embeddedPropertyReflection = new ReflectionEmbeddedProperty( - $parentProperty, - $childProperty, - $childProperty->getDeclaringClass()->getName() - ); + ReflectionProperty $childProperty, + $embeddableClass + ) { + $embeddedPropertyReflection = new ReflectionEmbeddedProperty($parentProperty, $childProperty, $embeddableClass); $instantiator = new Instantiator(); @@ -69,7 +65,7 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase /** * Data provider * - * @return ReflectionProperty[][] + * @return ReflectionProperty[][]|string[][] */ public function getTestedReflectionProperties() { @@ -83,6 +79,30 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', 'id' ), + 'Doctrine\\Tests\\Models\\Generic\\BooleanModel' + ), + // reflection on embeddables that have properties defined in abstract ancestors: + array( + $this->getReflectionProperty( + 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', + 'id' + ), + $this->getReflectionProperty( + 'Doctrine\\Tests\\Models\\Reflection\\AbstractEmbeddable', + 'propertyInAbstractClass' + ), + 'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable' + ), + array( + $this->getReflectionProperty( + 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', + 'id' + ), + $this->getReflectionProperty( + 'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable', + 'propertyInConcreteClass' + ), + 'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable' ), // reflection on classes extending internal PHP classes: array( @@ -94,6 +114,7 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', 'privateProperty' ), + 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass' ), array( $this->getReflectionProperty( @@ -104,6 +125,7 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', 'protectedProperty' ), + 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass' ), array( $this->getReflectionProperty( @@ -114,6 +136,7 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', 'publicProperty' ), + 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass' ), ); }