vendor/friendsofsymfony/elastica-bundle/src/Persister/Listener/FilterObjectsListener.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSElasticaBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace FOS\ElasticaBundle\Persister\Listener;
  11. use FOS\ElasticaBundle\Persister\Event\Events;
  12. use FOS\ElasticaBundle\Persister\Event\PreInsertObjectsEvent;
  13. use FOS\ElasticaBundle\Provider\IndexableInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class FilterObjectsListener implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var IndexableInterface
  19.      */
  20.     private $indexable;
  21.     public function __construct(IndexableInterface $indexable)
  22.     {
  23.         $this->indexable $indexable;
  24.     }
  25.     public function filterObjects(PreInsertObjectsEvent $event)
  26.     {
  27.         $options $event->getOptions();
  28.         if (false == empty($options['skip_indexable_check'])) {
  29.             return;
  30.         }
  31.         
  32.         $objects $event->getObjects();
  33.         $index $options['indexName'];
  34.         $type $options['typeName'];
  35.         $filtered = array();
  36.         foreach ($objects as $object) {
  37.             if (!$this->indexable->isObjectIndexable($index$type$object)) {
  38.                 continue;
  39.             }
  40.             $filtered[] = $object;
  41.         }
  42.         $event->setObjects($filtered);
  43.     }
  44.     /**
  45.      * {@inheritdoc}
  46.      */
  47.     public static function getSubscribedEvents()
  48.     {
  49.         return [Events::PRE_INSERT_OBJECTS => 'filterObjects'];
  50.     }
  51. }