-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
40 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
use Bazinga\GeocoderBundle\Mapping\Exception; | ||
use Doctrine\Common\Annotations\Reader; | ||
use Doctrine\Common\Util\ClassUtils; | ||
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver; | ||
|
||
/** | ||
* @author Markus Bachmann <[email protected]> | ||
|
@@ -32,14 +33,14 @@ public function __construct(Reader $reader) | |
|
||
public function isGeocodeable($object): bool | ||
{ | ||
$reflection = ClassUtils::newReflectionObject($object); | ||
$reflection = self::getReflection($object); | ||
|
||
return (bool) $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class); | ||
} | ||
|
||
public function loadMetadataFromObject($object) | ||
{ | ||
$reflection = ClassUtils::newReflectionObject($object); | ||
$reflection = self::getReflection($object); | ||
|
||
if (!$annotation = $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class)) { | ||
throw new Exception\MappingException(sprintf('The class %s is not geocodeable', get_class($object))); | ||
|
@@ -74,4 +75,13 @@ public function loadMetadataFromObject($object) | |
|
||
return $metadata; | ||
} | ||
|
||
private static function getReflection(object $object): \ReflectionClass | ||
{ | ||
if (class_exists(ClassUtils::class)) { | ||
return ClassUtils::newReflectionObject($object); | ||
} | ||
|
||
return new \ReflectionClass(DefaultProxyClassNameResolver::getClass($object)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
use Bazinga\GeocoderBundle\Mapping\ClassMetadata; | ||
use Bazinga\GeocoderBundle\Mapping\Exception\MappingException; | ||
use Doctrine\Common\Util\ClassUtils; | ||
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver; | ||
|
||
/** | ||
* @author Pierre du Plessis <[email protected]> | ||
|
@@ -28,7 +29,7 @@ public function isGeocodeable($object): bool | |
return false; | ||
} | ||
|
||
$reflection = ClassUtils::newReflectionObject($object); | ||
$reflection = self::getReflection($object); | ||
|
||
return count($reflection->getAttributes(Annotations\Geocodeable::class)) > 0; | ||
} | ||
|
@@ -42,7 +43,7 @@ public function loadMetadataFromObject($object): ClassMetadata | |
throw new MappingException(sprintf('The class %s is not geocodeable', get_class($object))); | ||
} | ||
|
||
$reflection = ClassUtils::newReflectionObject($object); | ||
$reflection = self::getReflection($object); | ||
|
||
$attributes = $reflection->getAttributes(Annotations\Geocodeable::class); | ||
|
||
|
@@ -79,4 +80,13 @@ public function loadMetadataFromObject($object): ClassMetadata | |
|
||
return $metadata; | ||
} | ||
|
||
private static function getReflection(object $object): \ReflectionClass | ||
{ | ||
if (class_exists(ClassUtils::class)) { | ||
return ClassUtils::newReflectionObject($object); | ||
} | ||
|
||
return new \ReflectionClass(DefaultProxyClassNameResolver::getClass($object)); | ||
} | ||
} |