vendor/enqueue/elastica-bundle/Persister/Listener/PurgePopulateQueueListener.php line 18

Open in your IDE?
  1. <?php
  2. namespace Enqueue\ElasticaBundle\Persister\Listener;
  3. use FOS\ElasticaBundle\Persister\Event\PrePersistEvent;
  4. use Interop\Queue\Context;
  5. use FOS\ElasticaBundle\Persister\Event\Events;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class PurgePopulateQueueListener implements EventSubscriberInterface
  8. {
  9.     private $context;
  10.     public function __construct(Context $context)
  11.     {
  12.         $this->context $context;
  13.     }
  14.     public function purgePopulateQueue(PrePersistEvent $event)
  15.     {
  16.         $options $event->getOptions();
  17.         if (empty($options['purge_populate_queue'])) {
  18.             return;
  19.         }
  20.         if (empty($options['populate_queue'])) {
  21.             return;
  22.         }
  23.         if (method_exists($this->context'purge')) {
  24.             $queue $this->context->createQueue($options['populate_queue']);
  25.             $this->context->purge($queue);
  26.         }
  27.         if (method_exists($this->context'purgeQueue')) {
  28.             $queue $this->context->createQueue($options['populate_queue']);
  29.             $this->context->purgeQueue($queue);
  30.         }
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     public static function getSubscribedEvents()
  36.     {
  37.         return [
  38.             Events::PRE_PERSIST => 'purgePopulateQueue',
  39.         ];
  40.     }
  41. }