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 | $this->setWrapLongitude($wrapLongitude); |
||
34 | } |
||
35 | |||
36 | public function isWrapLongitude(): bool |
||
37 | { |
||
38 | return $this->wrapLongitude; |
||
39 | } |
||
40 | |||
41 | public function setWrapLongitude(bool $wrapLongitude): static |
||
42 | { |
||
43 | $this->wrapLongitude = $wrapLongitude; |
||
44 | |||
45 | return $this; |
||
46 | } |
||
47 | |||
48 | public function getArray(): array |
||
49 | { |
||
50 | $data = []; |
||
51 | if ($this->getField()) { |
||
52 | $data['field'] = $this->getField(); |
||
53 | } else { |
||
54 | throw new \LogicException('Geo bounds aggregation must have a field set.'); |
||
55 | } |
||
56 | |||
57 | $data['wrap_longitude'] = $this->isWrapLongitude(); |
||
58 | |||
59 | return $data; |
||
60 | } |
||
61 | |||
62 | public function getType(): string |
||
63 | { |
||
64 | return 'geo_bounds'; |
||
65 | } |
||
66 | } |
||
67 |