Skip to content

Commit 143c799

Browse files
committed
Use Doctrine ClassUtils to detect proxy classes
1 parent d699405 commit 143c799

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

Mapping/Driver/AnnotationDriver.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Bazinga\GeocoderBundle\Mapping\ClassMetadata;
1717
use Bazinga\GeocoderBundle\Mapping\Exception;
1818
use Doctrine\Common\Annotations\Reader;
19+
use Doctrine\Common\Util\ClassUtils;
1920
use Doctrine\Persistence\Proxy;
2021

2122
/**
@@ -32,22 +33,14 @@ public function __construct(Reader $reader)
3233

3334
public function isGeocodeable($object): bool
3435
{
35-
$reflection = new \ReflectionObject($object);
36-
37-
if ($object instanceof Proxy) {
38-
$reflection = $reflection->getParentClass();
39-
}
36+
$reflection = ClassUtils::newReflectionObject($object);
4037

4138
return (bool) $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class);
4239
}
4340

4441
public function loadMetadataFromObject($object)
4542
{
46-
$reflection = new \ReflectionObject($object);
47-
48-
if ($object instanceof Proxy) {
49-
$reflection = $reflection->getParentClass();
50-
}
43+
$reflection = ClassUtils::newReflectionObject($object);
5144

5245
if (!$annotation = $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class)) {
5346
throw new Exception\MappingException(sprintf('The class %s is not geocodeable', get_class($object)));

0 commit comments

Comments
 (0)