1<?php 2 3namespace Elastica\Aggregation; 4 5use Elastica\Exception\InvalidException; 6 7/** 8 * Class PercentilesBucket. 9 * 10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html 11 */ 12class PercentilesBucket extends AbstractAggregation implements GapPolicyInterface 13{ 14 use Traits\BucketsPathTrait; 15 use Traits\GapPolicyTrait; 16 use Traits\KeyedTrait; 17 18 public function __construct(string $name, ?string $bucketsPath = null) 19 { 20 parent::__construct($name); 21 22 if (null !== $bucketsPath) { 23 $this->setBucketsPath($bucketsPath); 24 } elseif (\func_num_args() >= 2) { 25 \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing null as 2nd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); 26 } else { 27 \trigger_deprecation('ruflin/elastica', '7.1.3', 'Not passing a 2nd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); 28 } 29 } 30 31 /** 32 * @throws InvalidException If buckets path or script is not set 33 */ 34 public function toArray(): array 35 { 36 if (!$this->hasParam('buckets_path')) { 37 throw new InvalidException('Buckets path is required'); 38 } 39 40 return parent::toArray(); 41 } 42 43 /** 44 * Set the format for this aggregation. 45 */ 46 public function setFormat(string $format): self 47 { 48 return $this->setParam('format', $format); 49 } 50 51 /** 52 * Set which percents must be returned. 53 * 54 * @param float[] $percents 55 */ 56 public function setPercents(array $percents): self 57 { 58 return $this->setParam('percents', $percents); 59 } 60} 61