vendor/store.shopware.com/swagenterprisesearchplatform/src/Action/MultiSearch/MultiSearchActionSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Swag\EnterpriseSearch\Action\MultiSearch;
  4. use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
  5. use Swag\EnterpriseSearch\Action\ActionSearchProcessor;
  6. use Swag\EnterpriseSearch\Search\MultiSearchGatewayEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpFoundation\Request;
  9. class MultiSearchActionSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var ActionSearchProcessor
  13.      */
  14.     private $actionSearchProcessor;
  15.     public function __construct(ActionSearchProcessor $actionSearchProcessor)
  16.     {
  17.         $this->actionSearchProcessor $actionSearchProcessor;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             MultiSearchGatewayEvent::class => 'processActions',
  23.         ];
  24.     }
  25.     public function processActions(MultiSearchGatewayEvent $event): void
  26.     {
  27.         $context $event->getContext();
  28.         $request $event->getRequest();
  29.         $multiSearchActionProcessorEnvironment = new MultiSearchActionProcessorEnvironment($context$request);
  30.         $this->actionSearchProcessor->applySearchActions($context$this->getSearchTerm($request), $multiSearchActionProcessorEnvironment);
  31.     }
  32.     private function getSearchTerm(Request $request): string
  33.     {
  34.         $term $request->query->get('search');
  35.         if (is_array($term)) {
  36.             $term implode(' '$term);
  37.         }
  38.         $term trim((string) $term);
  39.         if (empty($term)) {
  40.             throw new MissingRequestParameterException('search');
  41.         }
  42.         return $term;
  43.     }
  44. }