Skip to content

Commit

Permalink
Fixes issue when getting annotation from Proxy
Browse files Browse the repository at this point in the history
Sometimes Doctrine will give you Proxy classes instead of the concrete class. When this happens the ReflectionClass will not be able to get the annotation from the Proxy class.
  • Loading branch information
mathewpeterson committed Jul 10, 2014
1 parent 261e487 commit 7187466
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Mapping/Driver/Annotation.php
Expand Up @@ -3,6 +3,7 @@
namespace Lexik\Bundle\MailerBundle\Mapping\Driver;

use Doctrine\Common\Annotations\Reader;
use Doctrine\ORM\Proxy\Proxy;

/**
* Driver to find values of annotated properties.
Expand Down Expand Up @@ -59,6 +60,11 @@ private function findValue($obj, $className)
{
$reflClass = new \ReflectionClass($obj);

// Make sure we are not using a Proxy class
if ($obj instanceof Proxy) {
$reflClass = $reflClass->getParentClass();
}

// Find on property
foreach ($reflClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
if ($this->reader->getPropertyAnnotation($property, $className)) {
Expand All @@ -73,4 +79,4 @@ private function findValue($obj, $className)
}
}
}
}
}

0 comments on commit 7187466

Please sign in to comment.