From eb2c7051bfb2255cdeed9151a53e6a3f112b8758 Mon Sep 17 00:00:00 2001 From: Kim Jeker Date: Wed, 6 Feb 2019 16:50:10 +0100 Subject: [PATCH 1/3] Update GeocoderListener.php prevented exception if address (or result) from geocoding is empty on doctrine entity geocoding --- Doctrine/ORM/GeocoderListener.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Doctrine/ORM/GeocoderListener.php b/Doctrine/ORM/GeocoderListener.php index 3194aac9..36db8c53 100644 --- a/Doctrine/ORM/GeocoderListener.php +++ b/Doctrine/ORM/GeocoderListener.php @@ -86,12 +86,19 @@ private function geocodeEntity($entity) { $metadata = $this->driver->loadMetadataFromObject($entity); $address = $metadata->addressProperty->getValue($entity); - $results = $this->geocoder->geocodeQuery(GeocodeQuery::create($address)); - - if (!empty($results)) { - $result = $results->first(); - $metadata->latitudeProperty->setValue($entity, $result->getCoordinates()->getLatitude()); - $metadata->longitudeProperty->setValue($entity, $result->getCoordinates()->getLongitude()); + if (!empty($address)) { + try { + $results = $this->geocoder->geocodeQuery(GeocodeQuery::create($address)); + + if (!empty($results)) { + $result = $results->first(); + $metadata->latitudeProperty->setValue($entity, $result->getCoordinates()->getLatitude()); + $metadata->longitudeProperty->setValue($entity, $result->getCoordinates()->getLongitude()); + } + } catch(\Geocoder\Exception\Exception $e) { + // todo log? + } } + } } From 8a76e538cbb089900017e6252edad9b2048026fa Mon Sep 17 00:00:00 2001 From: Kim Jeker Date: Wed, 6 Feb 2019 17:42:36 +0100 Subject: [PATCH 2/3] Update GeocoderListener.php --- Doctrine/ORM/GeocoderListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doctrine/ORM/GeocoderListener.php b/Doctrine/ORM/GeocoderListener.php index 36db8c53..9d73f961 100644 --- a/Doctrine/ORM/GeocoderListener.php +++ b/Doctrine/ORM/GeocoderListener.php @@ -95,7 +95,7 @@ private function geocodeEntity($entity) $metadata->latitudeProperty->setValue($entity, $result->getCoordinates()->getLatitude()); $metadata->longitudeProperty->setValue($entity, $result->getCoordinates()->getLongitude()); } - } catch(\Geocoder\Exception\Exception $e) { + } catch(\Exception $e) { // todo log? } } From a601ab3512a2be30f10b4ed00417aafe57fa4693 Mon Sep 17 00:00:00 2001 From: Kim Jeker Date: Wed, 6 Feb 2019 17:43:51 +0100 Subject: [PATCH 3/3] Update AnnotationDriver.php --- Mapping/Driver/AnnotationDriver.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Mapping/Driver/AnnotationDriver.php b/Mapping/Driver/AnnotationDriver.php index b8ec909e..967e789f 100644 --- a/Mapping/Driver/AnnotationDriver.php +++ b/Mapping/Driver/AnnotationDriver.php @@ -31,14 +31,27 @@ public function __construct(Reader $reader) public function isGeocodeable($object): bool { - $reflection = new \ReflectionObject($object); + $reflection = new \ReflectionClass($object); + + // check if object is a doctrine proxy object + if ($object instanceof \Doctrine\Common\Persistence\Proxy) { + // This gets the real object, the one that the Proxy extends + $reflection = $reflection->getParentClass(); + } return (bool) $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class); } public function loadMetadataFromObject($object) { - $reflection = new \ReflectionObject($object); + $reflection = new \ReflectionClass($object); + + // check if object is a doctrine proxy object + if ($object instanceof \Doctrine\Common\Persistence\Proxy) { + // This gets the real object, the one that the Proxy extends + $reflection = $reflection->getParentClass(); + } + if (!$annotation = $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class)) { throw new Exception\MappingException(sprintf( 'The class %s is not geocodeable', get_class($object)