Skip to content

Commit df49d18

Browse files
authored
Merge pull request #41 from terox/terox-reflection-private-properties
Read private properties from parent class
2 parents c20d8a3 + 9d34f61 commit df49d18

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/Vivait/StringGeneratorBundle/EventListener/GeneratorListener.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ public function prePersist(LifecycleEventArgs $args)
5151
$meta = $em->getClassMetadata(get_class($entity));
5252
$this->repo = $em->getRepository($meta->getName());
5353

54-
$object = new \ReflectionObject($entity);
54+
$currentObject = new \ReflectionObject($entity);
55+
$properties = [];
56+
do {
57+
foreach ($currentObject->getProperties() as $property) {
58+
$properties[] = $property;
59+
}
60+
} while (($currentObject = $currentObject->getParentClass()) && (false !== $currentObject));
5561

56-
foreach ($object->getProperties() as $property) {
62+
/** @var \ReflectionProperty[] $property */
63+
foreach ($properties as $property) {
5764
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
5865
if ($annotation instanceof GeneratorAnnotation) {
5966

0 commit comments

Comments
 (0)