diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-18 06:00:00 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-18 06:00:00 +0100 |
commit | 15e69f7b20b6596b9148030acce5b59993b95a45 (patch) | |
tree | 7b828b8920b0e222dc2a2c97dde933c9c4864fab /vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.25.4
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php new file mode 100644 index 00000000..5ad5b17e --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php @@ -0,0 +1,88 @@ +<?php + +namespace Elastica\Aggregation; + +use Elastica\Param; +use Elastica\Exception\InvalidException; + +abstract class AbstractAggregation extends Param +{ + /** + * The name of this aggregation + * @var string + */ + protected $_name; + + /** + * Subaggregations belonging to this aggregation + * @var array + */ + protected $_aggs = array(); + + /** + * @param string $name the name of this aggregation + */ + public function __construct($name) + { + $this->setName($name); + } + + /** + * Set the name of this aggregation + * @param string $name + */ + public function setName($name) + { + $this->_name = $name; + } + + /** + * Retrieve the name of this aggregation + * @return string + */ + public function getName() + { + return $this->_name; + } + + /** + * Retrieve all subaggregations belonging to this aggregation + * @return array + */ + public function getAggs() + { + return $this->_aggs; + } + + /** + * Add a sub-aggregation + * @param AbstractAggregation $aggregation + * @throws \Elastica\Exception\InvalidException + * @return AbstractAggregation + */ + public function addAggregation(AbstractAggregation $aggregation) + { + if(is_a($aggregation, 'Elastica\Aggregation\GlobalAggregation')) { + throw new InvalidException('Global aggregators can only be placed as top level aggregators'); + } + + $this->_aggs[$aggregation->getName()] = $aggregation->toArray(); + return $this; + } + + /** + * @return array + */ + public function toArray() + { + $array = parent::toArray(); + if (array_key_exists('global_aggregation', $array)) { + // compensate for class name GlobalAggregation + $array = array('global' => new \stdClass); + } + if (sizeof($this->_aggs)) { + $array['aggs'] = $this->_aggs; + } + return $array; + } +}
\ No newline at end of file |