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

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 Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class PurgePopulateQueueListener implements EventSubscriberInterface
  7. {
  8.     private $context;
  9.     public function __construct(Context $context)
  10.     {
  11.         $this->context $context;
  12.     }
  13.     public function purgePopulateQueue(PrePersistEvent $event)
  14.     {
  15.         $options $event->getOptions();
  16.         if (empty($options['purge_populate_queue'])) {
  17.             return;
  18.         }
  19.         if (empty($options['populate_queue'])) {
  20.             return;
  21.         }
  22.         if (method_exists($this->context'purge')) {
  23.             $queue $this->context->createQueue($options['populate_queue']);
  24.             $this->context->purge($queue);
  25.         }
  26.         if (method_exists($this->context'purgeQueue')) {
  27.             $queue $this->context->createQueue($options['populate_queue']);
  28.             $this->context->purgeQueue($queue);
  29.         }
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return [
  37.             PrePersistEvent::class => 'purgePopulateQueue',
  38.         ];
  39.     }
  40. }