| 1 | <?php |
||
| 20 | class FiltersAggregation extends AbstractAggregation |
||
| 21 | { |
||
| 22 | use BucketingTrait; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var BuilderInterface[] |
||
| 26 | */ |
||
| 27 | private $filters = []; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var bool |
||
| 31 | */ |
||
| 32 | private $anonymous = false; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param bool $anonymous |
||
| 36 | * |
||
| 37 | * @return FiltersAggregation |
||
| 38 | */ |
||
| 39 | public function setAnonymous($anonymous) |
||
| 40 | { |
||
| 41 | $this->anonymous = $anonymous; |
||
| 42 | |||
| 43 | return $this; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param BuilderInterface $filter |
||
| 48 | * @param string $name |
||
| 49 | * |
||
| 50 | * @throws \LogicException |
||
| 51 | * |
||
| 52 | * @return FiltersAggregation |
||
| 53 | */ |
||
| 54 | public function addFilter(BuilderInterface $filter, $name = '') |
||
| 55 | { |
||
| 56 | if ($this->anonymous === false && empty($name)) { |
||
| 57 | throw new \LogicException('In not anonymous filters filter name must be set.'); |
||
| 58 | } elseif ($this->anonymous === false && !empty($name)) { |
||
| 59 | $this->filters['filters'][$name] = [$filter->getType() => $filter->toArray()]; |
||
| 60 | } else { |
||
| 61 | $this->filters['filters'][] = [$filter->getType() => $filter->toArray()]; |
||
| 62 | } |
||
| 63 | |||
| 64 | return $this; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritdoc} |
||
| 69 | */ |
||
| 70 | public function getArray() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * {@inheritdoc} |
||
| 77 | */ |
||
| 78 | public function getType() |
||
| 82 | } |
||
| 83 |