vendor/shopware/core/Framework/DataAbstractionLayer/Search/Aggregation/Bucket/FilterAggregation.php line 11

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Bucket;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Aggregation;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\Filter;
  5. use Shopware\Core\Framework\Log\Package;
  6. /**
  7.  * @final
  8.  */
  9. #[Package('core')]
  10. class FilterAggregation extends BucketAggregation
  11. {
  12.     /**
  13.      * @param Filter[] $filter
  14.      */
  15.     public function __construct(
  16.         string $name,
  17.         Aggregation $aggregation,
  18.         protected array $filter
  19.     ) {
  20.         parent::__construct($name''$aggregation);
  21.     }
  22.     /**
  23.      * @return Filter[]
  24.      */
  25.     public function getFilter(): array
  26.     {
  27.         return $this->filter;
  28.     }
  29.     public function getField(): string
  30.     {
  31.         return $this->aggregation?->getField() ?? '';
  32.     }
  33.     public function getFields(): array
  34.     {
  35.         $fields $this->aggregation?->getFields() ?? [];
  36.         foreach ($this->filter as $filter) {
  37.             $nested $filter->getFields();
  38.             foreach ($nested as $field) {
  39.                 $fields[] = $field;
  40.             }
  41.         }
  42.         return $fields;
  43.     }
  44.     /**
  45.      * @param Filter[] $filters
  46.      */
  47.     public function addFilters(array $filters): void
  48.     {
  49.         foreach ($filters as $filter) {
  50.             $this->filter[] = $filter;
  51.         }
  52.     }
  53. }