Skip to content
Snippets Groups Projects
Commit 445693f8 authored by Martynas Sudintas's avatar Martynas Sudintas
Browse files

Merge pull request #285 from chyzas/patch-dsl-aggregations

Added IPv4 aggregation
parents db48c6c7 6cda6c4f
No related merge requests found
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Aggregation;
use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait;
/**
* Class representing ip range aggregation.
*/
class Ipv4RangeAggregation extends AbstractAggregation
{
use BucketingTrait;
/**
* @var array
*/
private $ranges = [];
/**
* Add range to aggregation.
*
* @param string|null $from
* @param string|null $to
*
* @return Ipv4RangeAggregation
*/
public function addRange($from = null, $to = null)
{
$range = array_filter(
[
'from' => $from,
'to' => $to,
]
);
$this->ranges[] = $range;
return $this;
}
/**
* Add ip mask to aggregation.
*
* @param string $mask
*
* @return Ipv4RangeAggregation
*/
public function addMask($mask)
{
$this->ranges[] = ['mask' => $mask];
return $this;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'ip_range';
}
/**
* {@inheritdoc}
*/
public function getArray()
{
if ($this->getField() && !empty($this->ranges)) {
return [
'field' => $this->getField(),
'ranges' => array_values($this->ranges),
];
}
throw new \LogicException('Ip range aggregation must have field set and range added.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment