src/WellCommerce/Bundle/AppBundle/EventListener/PushNotificationSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=0);
  3. /*
  4.  * WellCommerce Foundation
  5.  *
  6.  * This file is part of the WellCommerce package.
  7.  *
  8.  * (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
  9.  *
  10.  * For the full copyright and license information,
  11.  * please view the LICENSE file that was distributed with this source code.
  12.  */
  13. namespace WellCommerce\Bundle\AppBundle\EventListener;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use WellCommerce\Bundle\AppBundle\Entity\PushNotification;
  16. use WellCommerce\Bundle\CoreBundle\DependencyInjection\AbstractServiceSubscriber;
  17. use WellCommerce\Bundle\CoreBundle\Doctrine\Event\EntityEvent;
  18. class PushNotificationSubscriber extends AbstractServiceSubscriber implements EventSubscriberInterface
  19. {
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             'push_notification.post_init'   => ['onPushNotificationInit'0],
  24.             'push_notification.post_create' => ['onPushNotificationCreate'0],
  25.         ];
  26.     }
  27.     public function onPushNotificationInit(EntityEvent $event)
  28.     {
  29.         $resource $event->getEntity();
  30.         if ($resource instanceof PushNotification) {
  31.             $channel $this->getKernel()->getContainer()->getParameter('pusher_channel');
  32.             $resource->setChannel($channel);
  33.         }
  34.     }
  35.     public function onPushNotificationCreate(EntityEvent $event)
  36.     {
  37.         $resource $event->getEntity();
  38.         if ($resource instanceof PushNotification) {
  39.             $this->getPusherHelper()->publishToInterests(
  40.                 [$resource->getChannel()],
  41.                 $resource->getTitle(),
  42.                 $resource->getContent()
  43.             );
  44.         }
  45.     }
  46. }