src/EventSubscriber/NotificationSubscriber.php line 53

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\EventSubscriber;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Gos\Bundle\WebSocketBundle\Pusher\PusherInterface;
  7. use App\Event\NotificationCreatedEvent;
  8. class NotificationSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var PusherInterface
  12.      */
  13.     private $pusher;
  14.     /**
  15.      * @var EntityManagerInterface
  16.      */
  17.     private $entityManager;
  18.     /**
  19.      * NotificationSubscriber constructor.
  20.      * @param PusherInterface $pusher
  21.      * @param EntityManagerInterface $entityManager
  22.      */
  23.     public function __construct(PusherInterface $pusherEntityManagerInterface $entityManager)
  24.     {
  25.         $this->pusher $pusher;
  26.         $this->entityManager $entityManager;
  27.     }
  28.     /**
  29.      * @return array
  30.      */
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             NotificationCreatedEvent::class => [
  35.                 ['onNotificationCreated'10]
  36.             ],
  37.         ];
  38.     }
  39.     /**
  40.      * @param NotificationCreatedEvent $event
  41.      */
  42.     public function onNotificationCreated(NotificationCreatedEvent $event)
  43.     {
  44.         $notification $event->getNotification();
  45.         $this->entityManager->persist($notification);
  46.        // $socketResponse = 'ready';
  47.        // $this->pusher->push($socketResponse, 'acme_topic', []);
  48.     }
  49. }