| 1 | <?php |
||
| 22 | * @link http://goo.gl/aGqw7Y |
||
| 23 | */ |
||
| 24 | class GeoBoundsAggregation extends AbstractAggregation |
||
| 25 | { |
||
| 26 | use MetricTrait; |
||
| 27 | |||
| 28 | public function __construct(private string $name, private ?string $field = null, private bool $wrapLongitude = true) |
||
|
|
|||
| 29 | { |
||
| 30 | parent::__construct($name); |
||
| 31 | |||
| 32 | $this->setField($field); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function isWrapLongitude(): bool |
||
| 36 | { |
||
| 37 | return $this->wrapLongitude; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function setWrapLongitude(bool $wrapLongitude): static |
||
| 41 | { |
||
| 42 | $this->wrapLongitude = $wrapLongitude; |
||
| 43 | |||
| 44 | return $this; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getArray(): array |
||
| 48 | { |
||
| 49 | $data = []; |
||
| 50 | if ($this->getField()) { |
||
| 51 | $data['field'] = $this->getField(); |
||
| 52 | } else { |
||
| 53 | throw new \LogicException('Geo bounds aggregation must have a field set.'); |
||
| 54 | } |
||
| 55 | |||
| 56 | $data['wrap_longitude'] = $this->isWrapLongitude(); |
||
| 57 | |||
| 58 | return $data; |
||
| 59 | } |
||
| 60 | |||
| 61 | public function getType(): string |
||
| 62 | { |
||
| 63 | return 'geo_bounds'; |
||
| 64 | } |
||
| 65 | } |
||
| 66 |