vendor/pimcore/advanced-object-search/src/Event/AbstractFilterListener.php line 79

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace AdvancedObjectSearchBundle\Event;
  15. use AdvancedObjectSearchBundle\Service;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. use Symfony\Component\HttpFoundation\ParameterBag;
  18. use Symfony\Component\HttpFoundation\RequestStack;
  19. abstract class AbstractFilterListener implements EventSubscriberInterface
  20. {
  21.     /**
  22.      * @var ParameterBag
  23.      */
  24.     protected $parameters;
  25.     /**
  26.      * @var Service
  27.      */
  28.     protected $service;
  29.     public function __construct(RequestStack $requestStackService $service)
  30.     {
  31.         $request $requestStack->getCurrentRequest();
  32.         $this->service $service;
  33.         if ($request) {
  34.             $this->parameters = new ParameterBag(json_decode($request->get('customFilter'), true) ?: []);
  35.         } else {
  36.             $this->parameters = new ParameterBag([]);
  37.         }
  38.     }
  39.     /**
  40.      * @return ParameterBag
  41.      */
  42.     protected function getParameters(): ParameterBag
  43.     {
  44.         return $this->parameters;
  45.     }
  46.     /**
  47.      * @return Service
  48.      */
  49.     protected function getService(): Service
  50.     {
  51.         return $this->service;
  52.     }
  53.     /**
  54.      * {@inheritdoc}
  55.      */
  56.     public static function getSubscribedEvents()
  57.     {
  58.         return [
  59.             AdvancedObjectSearchEvents::ELASITIC_FILTER => [
  60.                 ['onElasticSearch'10],
  61.             ],
  62.             AdvancedObjectSearchEvents::LISTING_FILER => [
  63.                 ['onListing'10]
  64.             ]
  65.         ];
  66.     }
  67.     public function onElasticSearch(FilterSearchEvent $event)
  68.     {
  69.         if ($this->supports()) {
  70.             $this->addElasticSearchFilter($event);
  71.         }
  72.     }
  73.     public function onListing(FilterListingEvent $event)
  74.     {
  75.         if ($this->supports()) {
  76.             $this->addListingFiler($event);
  77.         }
  78.     }
  79.     /**
  80.      * @return bool
  81.      */
  82.     abstract protected function supports(): bool;
  83.     /**
  84.      * @param FilterSearchEvent $event
  85.      *
  86.      * @return void
  87.      */
  88.     protected function addElasticSearchFilter(FilterSearchEvent $event)
  89.     {
  90.     }
  91.     /**
  92.      * @param FilterListingEvent $event
  93.      *
  94.      * @return void
  95.      */
  96.     protected function addListingFiler(FilterListingEvent $event)
  97.     {
  98.     }
  99. }