<?php
declare(strict_types=1);
namespace Harmonizely\EventListener;
use Harmonizely\Model\CalendarAccountInterface;
use Harmonizely\Model\User;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Webmozart\Assert\Assert;
final class UserCalendarAccountListener
{
private $tokenStorage;
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}
public function update(GenericEvent $event): void
{
$subject = $event->getSubject();
Assert::isInstanceOf($subject, CalendarAccountInterface::class);
/** @var User $user */
$user = $this->tokenStorage->getToken()->getUser();
$user->addCalendarAccount($subject);
}
}