src/EventSubscriber/Geographical/AddCustomerToAddressSubscriber.php line 40
<?php/** This file is part of the Pellipop project.** (c) Mobizel** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/declare(strict_types=1);namespace App\EventSubscriber\Geographical;use ApiPlatform\Symfony\EventListener\EventPriorities;use App\Entity\Geographical\Address;use Sylius\Component\Customer\Context\CustomerContextInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpKernel\Event\ViewEvent;use Symfony\Component\HttpKernel\KernelEvents;final class AddCustomerToAddressSubscriber implements EventSubscriberInterface{private CustomerContextInterface $customerContext;public function __construct(CustomerContextInterface $customerContext){$this->customerContext = $customerContext;}public static function getSubscribedEvents(): array{return [KernelEvents::VIEW => ['attachCustomer', EventPriorities::PRE_WRITE],];}public function attachCustomer(ViewEvent $event): void{/** @var Address $address */$address = $event->getControllerResult();$method = $event->getRequest()->getMethod();if (!$address instanceof Address || Request::METHOD_POST !== $method) {return;}$address->setCustomer($this->customerContext->getCustomer());}}