← Back
Editing: AddressAssignGeocode.php
<?php namespace App\EventListener; use App\Entity\Adresse; use App\Service\GeoService; use Doctrine\Persistence\Event\LifecycleEventArgs; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; class AddressAssignGeocode { private GeoService $geoService; public function __construct(GeoService $geoService) { $this->geoService = $geoService; } /** * @return void * * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ private function fillGeocode(LifecycleEventArgs $args) { if (!$args->getObject() instanceof Adresse) { return; } /** @var Adresse $address */ $address = $args->getObject(); if (!$address->getLat() && !$address->getLng()) { $this->geoService->assignGeoFromAddress($address); } } public function preUpdate(LifecycleEventArgs $args): void { $this->fillGeocode($args); } public function prePersist(LifecycleEventArgs $args): void { $this->fillGeocode($args); } }
Save File
Cancel