1<?php 2 3namespace Elastica\Query; 4 5/** 6 * geo_shape query for provided shapes. 7 * 8 * Query provided shape definitions 9 * 10 * @author BennieKrijger <benniekrijger@gmail.com> 11 * 12 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html 13 */ 14class GeoShapeProvided extends AbstractGeoShape 15{ 16 public const TYPE_ENVELOPE = 'envelope'; 17 public const TYPE_MULTIPOINT = 'multipoint'; 18 public const TYPE_POINT = 'point'; 19 public const TYPE_MULTIPOLYGON = 'multipolygon'; 20 public const TYPE_LINESTRING = 'linestring'; 21 public const TYPE_POLYGON = 'polygon'; 22 23 /** 24 * Type of the geo_shape. 25 * 26 * @var string 27 */ 28 protected $_shapeType; 29 30 /** 31 * Coordinates making up geo_shape. 32 * 33 * @var array Coordinates making up geo_shape 34 */ 35 protected $_coordinates; 36 37 /** 38 * Construct geo_shape query. 39 * 40 * @param string $path The path/field of the shape searched 41 * @param array $coordinates Points making up the shape 42 * @param string $shapeType Type of the geo_shape: 43 * point, envelope, linestring, polygon, 44 * multipoint or multipolygon 45 */ 46 public function __construct(string $path, array $coordinates, string $shapeType = self::TYPE_ENVELOPE) 47 { 48 $this->_path = $path; 49 $this->_shapeType = $shapeType; 50 $this->_coordinates = $coordinates; 51 } 52 53 /** 54 * {@inheritdoc} 55 */ 56 public function toArray(): array 57 { 58 return [ 59 'geo_shape' => [ 60 $this->_path => [ 61 'shape' => [ 62 'type' => $this->_shapeType, 63 'coordinates' => $this->_coordinates, 64 ], 65 'relation' => $this->_relation, 66 ], 67 ], 68 ]; 69 } 70} 71