summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:47 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:47 -0400
commit7e85254903c7c0cb49e381f16b18441ea7b058cc (patch)
treeb22328fcf4c8408fc25a7acb73d1cb1089cd82ac /vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php
parent1de335ad3f395ca6861085393ba366a9e3fb4a0d (diff)
parent1a365e77dfb8825136626202b1df462731b42060 (diff)
Merge commit '1a365e'
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php88
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