<?php
namespace Aqarmap\Bundle\NotificationBundle;
use Aqarmap\Bundle\NotificationBundle\Types\UserWasSignup;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class UserSubscriber implements EventSubscriberInterface
{
/**
* EventDispatcherInterface instance.
*
* @var EventDispatcherInterface
*/
public $dispatcher;
/**
* Create a user subscriber instance.
*/
public function __construct(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
}
/**
* Register the listeners for the subscriber.
*/
public static function getSubScribedEvents()
{
return [
FOSUserEvents::REGISTRATION_COMPLETED => 'onRegistrationCompleted',
];
}
/**
* Send notification when registration completed.
*/
public function onRegistrationCompleted(FilterUserResponseEvent $event): void
{
$this->dispatcher->dispatch(new UserWasSignup($event->getUser()), 'user.was.signup');
}
}