src/FlexApp/EventSubscriber/CommentSendToPortalSubscriber.php line 65

Open in your IDE?
  1. <?php
  2. namespace FlexApp\EventSubscriber;
  3. use FlexApp\Events\CommentEvent;
  4. use FlexApp\Events\Style43\CommentCreateFromFormSavedSuccessfullyEvent;
  5. use FlexApp\Events\Style43\CommentUpdateFromFormSavedSuccessfullyEvent;
  6. use FlexApp\Events\Style43\ExistingCommentSavedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use WebBundle\Helper\PortalHelper;
  9. class CommentSendToPortalSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var PortalHelper
  13.      */
  14.     private $portalHelper;
  15.     /**
  16.      * CommentSendToPortalSubscriber constructor.
  17.      */
  18.     public function __construct(PortalHelper $portalHelper)
  19.     {
  20.         $this->portalHelper $portalHelper;
  21.     }
  22.     /**
  23.      * Returns an array of event names this subscriber wants to listen to.
  24.      *
  25.      * The array keys are event names and the value can be:
  26.      *
  27.      *  * The method name to call (priority defaults to 0)
  28.      *  * An array composed of the method name to call and the priority
  29.      *  * An array of arrays composed of the method names to call and respective
  30.      *    priorities, or 0 if unset
  31.      *
  32.      * For instance:
  33.      *
  34.      *  * array('eventName' => 'methodName')
  35.      *  * array('eventName' => array('methodName', $priority))
  36.      *  * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
  37.      *
  38.      * @return array The event names to listen to
  39.      */
  40.     public static function getSubscribedEvents()
  41.     {
  42.         return [
  43.             CommentCreateFromFormSavedSuccessfullyEvent::class => [
  44.                 ['send', -5],
  45. //              ['anotherMethodWhichInvokesWhenEventOccurs', 10],
  46.             ],
  47.             CommentUpdateFromFormSavedSuccessfullyEvent::class => [
  48.                 ['send', -5],
  49.             ],
  50.             ExistingCommentSavedEvent::class => [
  51.                 ['sendExistingComment'0],
  52.             ],
  53.         ];
  54.     }
  55.     /**
  56.      * При возникновении перечисленных событий отправляет
  57.      * коммент на портал с помощью PortalHelper.
  58.      */
  59.     public function send(CommentEvent $commentEvent)
  60.     {
  61.         $comment $commentEvent->getComment();
  62.         $this->portalHelper->sendCommentEntity($comment);
  63.     }
  64.     public function sendExistingComment(CommentEvent $commentEvent)
  65.     {
  66.         $comment $commentEvent->getComment();
  67.         $this->portalHelper->sendUpdateCommentEntity($comment);
  68.     }
  69. }