<?php declare(strict_types=1);
namespace App\Subscriber;
use App\Entity\User;
use App\Event\Recurring\MembershipCancel;
use App\Event\UserRolesChangedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class MembershipCancelSubscriber implements EventSubscriberInterface
{
public function onCancel(MembershipCancel $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 [
MembershipCancel::class => 'onCancel',
];
}
}