<?php declare(strict_types=1);
namespace App\Subscriber;
use App\Entity\User;
use App\Event\Recurring\MembershipAdd;
use App\Event\UserRolesChangedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class MembershipAddSubscriber implements EventSubscriberInterface
{
public function onAdd(MembershipAdd $addEvent, string $eventName, EventDispatcherInterface $eventDispatcher): void
{
$user = $addEvent->getUser();
if (!$user instanceof User) {
throw new UnexpectedTypeException($user, User::class);
}
$eventDispatcher->dispatch(new UserRolesChangedEvent($user));
}
/**
* @return array<string, array<int|string, array<int|string, int|string>|int|string>|string>
*/
public static function getSubscribedEvents(): array
{
return [
MembershipAdd::class => 'onAdd',
];
}
}