Skip to content

Some Fixes for Doctrine Annotations #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Doctrine/ORM/GeocoderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(\Exception $e) {
// todo log?
}
}

}
}
17 changes: 15 additions & 2 deletions Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down