src/EventSubscriber/User/ProfileSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. /*
  3.  * @since 1.0.0
  4.  * @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
  5.  * @website http://artmedia.biz.pl
  6.  * @author Arkadiusz Tobiasz
  7.  * @email kontakt@artmedia.biz.pl
  8.  */
  9. namespace App\EventSubscriber\User;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use App\Events\User\ProfileCreatedEvent;
  13. class ProfileSubscriber implements EventSubscriberInterface
  14. {
  15.     private $em;
  16.     public function __construct(
  17.         EntityManagerInterface $em
  18.     ) {
  19.         $this->em $em;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             ProfileCreatedEvent::NAME => 'onProfileCreatedEvent',
  25.         ];
  26.     }
  27.     public function onProfileCreatedEvent(ProfileCreatedEvent $event): void
  28.     {
  29.         $user $event->getProfile()->getUser();
  30.         $profile $event->getProfile();
  31.         $profile->setCity($user->getCity());
  32.         $profile->setCountry($user->getCountry());
  33.         $profile->setLocation($user->getLocation());
  34.         $this->em->flush();
  35.     }
  36. }