src/EventListener/UserCalendarAccountListener.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Harmonizely\EventListener;
  4. use Harmonizely\Model\CalendarAccountInterface;
  5. use Harmonizely\Model\User;
  6. use Symfony\Component\EventDispatcher\GenericEvent;
  7. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  8. use Webmozart\Assert\Assert;
  9. final class UserCalendarAccountListener
  10. {
  11.     private $tokenStorage;
  12.     public function __construct(TokenStorageInterface $tokenStorage)
  13.     {
  14.         $this->tokenStorage $tokenStorage;
  15.     }
  16.     public function update(GenericEvent $event): void
  17.     {
  18.         $subject $event->getSubject();
  19.         Assert::isInstanceOf($subjectCalendarAccountInterface::class);
  20.         /** @var User $user */
  21.         $user $this->tokenStorage->getToken()->getUser();
  22.         $user->addCalendarAccount($subject);
  23.     }
  24. }