<?php
namespace Aqarmap\Bundle\ListingBundle\EventListener;
use Aqarmap\Bundle\ListingBundle\Event\LocationSearchHistoryEvent;
use Aqarmap\Bundle\MainBundle\Constant\ProducerQueues;
use Aqarmap\Bundle\MainBundle\Contract\ProducerFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class LocationSearchHistorySubscriber.
*/
class LocationSearchHistorySubscriber implements EventSubscriberInterface
{
/**
* @var ProducerFactoryInterface
*/
private $producerFactory;
public function __construct(ProducerFactoryInterface $producerFactory)
{
$this->producerFactory = $producerFactory;
}
/**
* Producer.
*/
public function onLocationSearch(LocationSearchHistoryEvent $locationSearchHistoryEvent): void
{
$locationKeyword = $locationSearchHistoryEvent->getLocationKeyword();
$this->producerFactory
->create(ProducerQueues::RECORD_LOCATION_SEARCH_HISTORY)
->publish(
serialize(
[
'location_keyword' => $locationKeyword,
]
)
)
;
$locationSearchHistoryEvent->stopPropagation();
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
LocationSearchHistoryEvent::CREATE => 'onLocationSearch',
];
}
}