1<?php 2 3namespace Elastica\Query; 4 5/** 6 * Geo polygon query. 7 * 8 * @author Michael Maclean <mgdm@php.net> 9 * 10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html 11 */ 12class GeoPolygon extends AbstractQuery 13{ 14 /** 15 * Key. 16 * 17 * @var string Key 18 */ 19 protected $_key; 20 21 /** 22 * Points making up polygon. 23 * 24 * @var array Points making up polygon 25 */ 26 protected $_points; 27 28 /** 29 * Construct polygon query. 30 * 31 * @param string $key Key 32 * @param array $points Points making up polygon 33 */ 34 public function __construct(string $key, array $points) 35 { 36 $this->_key = $key; 37 $this->_points = $points; 38 } 39 40 /** 41 * {@inheritdoc} 42 */ 43 public function toArray(): array 44 { 45 return [ 46 'geo_polygon' => [ 47 $this->_key => [ 48 'points' => $this->_points, 49 ], 50 ], 51 ]; 52 } 53 54 /** 55 * {@inheritdoc} 56 */ 57 public function count(): int 58 { 59 return \count($this->_points); 60 } 61} 62