src/Aqarmap/Bundle/ListingBundle/EventListener/LocationSearchHistorySubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace Aqarmap\Bundle\ListingBundle\EventListener;
  3. use Aqarmap\Bundle\ListingBundle\Event\LocationSearchHistoryEvent;
  4. use Aqarmap\Bundle\MainBundle\Constant\ProducerQueues;
  5. use Aqarmap\Bundle\MainBundle\Contract\ProducerFactoryInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. /**
  8.  * Class LocationSearchHistorySubscriber.
  9.  */
  10. class LocationSearchHistorySubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var ProducerFactoryInterface
  14.      */
  15.     private $producerFactory;
  16.     public function __construct(ProducerFactoryInterface $producerFactory)
  17.     {
  18.         $this->producerFactory $producerFactory;
  19.     }
  20.     /**
  21.      * Producer.
  22.      */
  23.     public function onLocationSearch(LocationSearchHistoryEvent $locationSearchHistoryEvent): void
  24.     {
  25.         $locationKeyword $locationSearchHistoryEvent->getLocationKeyword();
  26.         $this->producerFactory
  27.             ->create(ProducerQueues::RECORD_LOCATION_SEARCH_HISTORY)
  28.             ->publish(
  29.                 serialize(
  30.                     [
  31.                         'location_keyword' => $locationKeyword,
  32.                     ]
  33.                 )
  34.             )
  35.         ;
  36.         $locationSearchHistoryEvent->stopPropagation();
  37.     }
  38.     /**
  39.      * @return array
  40.      */
  41.     public static function getSubscribedEvents()
  42.     {
  43.         return [
  44.             LocationSearchHistoryEvent::CREATE => 'onLocationSearch',
  45.         ];
  46.     }
  47. }