<?php
declare(strict_types=1);
namespace App\EventSubscriber;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Gos\Bundle\WebSocketBundle\Pusher\PusherInterface;
use App\Event\NotificationCreatedEvent;
class NotificationSubscriber implements EventSubscriberInterface
{
/**
* @var PusherInterface
*/
private $pusher;
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* NotificationSubscriber constructor.
* @param PusherInterface $pusher
* @param EntityManagerInterface $entityManager
*/
public function __construct(PusherInterface $pusher, EntityManagerInterface $entityManager)
{
$this->pusher = $pusher;
$this->entityManager = $entityManager;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
NotificationCreatedEvent::class => [
['onNotificationCreated', 10]
],
];
}
/**
* @param NotificationCreatedEvent $event
*/
public function onNotificationCreated(NotificationCreatedEvent $event)
{
$notification = $event->getNotification();
$this->entityManager->persist($notification);
// $socketResponse = 'ready';
// $this->pusher->push($socketResponse, 'acme_topic', []);
}
}