<?php
/*
* @since 1.0.0
* @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
* @website http://artmedia.biz.pl
* @author Arkadiusz Tobiasz
* @email kontakt@artmedia.biz.pl
*/
namespace App\EventSubscriber\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Events\User\ProfileCreatedEvent;
class ProfileSubscriber implements EventSubscriberInterface
{
private $em;
public function __construct(
EntityManagerInterface $em
) {
$this->em = $em;
}
public static function getSubscribedEvents(): array
{
return [
ProfileCreatedEvent::NAME => 'onProfileCreatedEvent',
];
}
public function onProfileCreatedEvent(ProfileCreatedEvent $event): void
{
$user = $event->getProfile()->getUser();
$profile = $event->getProfile();
$profile->setCity($user->getCity());
$profile->setCountry($user->getCountry());
$profile->setLocation($user->getLocation());
$this->em->flush();
}
}