vendor/shopware/core/Framework/DataAbstractionLayer/Search/Filter/MultiFilter.php line 8

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\DataAbstractionLayer\Search\Filter;
  3. use Shopware\Core\Framework\Log\Package;
  4. /**
  5.  * @phpstan-ignore-next-line cannot be final, as it is extended, also designed to be used directly
  6.  */
  7. #[Package('core')]
  8. class MultiFilter extends Filter
  9. {
  10.     public const CONNECTION_AND 'AND';
  11.     public const CONNECTION_OR 'OR';
  12.     public const CONNECTION_XOR 'XOR';
  13.     public const VALID_OPERATORS = [
  14.         self::CONNECTION_AND,
  15.         self::CONNECTION_OR,
  16.         self::CONNECTION_XOR,
  17.     ];
  18.     protected string $operator;
  19.     /**
  20.      * @param array<Filter> $queries
  21.      */
  22.     public function __construct(
  23.         string $operator,
  24.         protected array $queries = []
  25.     ) {
  26.         $this->operator mb_strtoupper(trim($operator));
  27.         if (!\in_array($this->operatorself::VALID_OPERATORStrue)) {
  28.             throw new \InvalidArgumentException('Operator ' $this->operator ' not allowed');
  29.         }
  30.     }
  31.     public function addQuery(Filter $query): self
  32.     {
  33.         $this->queries[] = $query;
  34.         return $this;
  35.     }
  36.     /**
  37.      * @return array<Filter>
  38.      */
  39.     public function getQueries(): array
  40.     {
  41.         return $this->queries;
  42.     }
  43.     public function getOperator(): string
  44.     {
  45.         if (!\in_array($this->operatorself::VALID_OPERATORStrue)) {
  46.             throw new \InvalidArgumentException('Operator ' $this->operator ' not allowed');
  47.         }
  48.         return $this->operator;
  49.     }
  50.     public function getFields(): array
  51.     {
  52.         $fields = [];
  53.         foreach ($this->queries as $query) {
  54.             foreach ($query->getFields() as $field) {
  55.                 $fields[] = $field;
  56.             }
  57.         }
  58.         return $fields;
  59.     }
  60. }