forked from ruflin/Elastica
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom range key and refactor addRange in a trait
- Loading branch information
Showing
6 changed files
with
118 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Elastica\Aggregation\Traits; | ||
|
||
use Elastica\Exception\InvalidException; | ||
|
||
trait RangeTrait | ||
{ | ||
/** | ||
* Add a range to this aggregation. | ||
* | ||
* @param float|int|string|null $fromValue low end of this range, exclusive (greater than or equal to) | ||
* @param float|int|string|null $toValue high end of this range, exclusive (less than) | ||
* @param string|null $key customized key value | ||
* | ||
* @throws InvalidException | ||
* | ||
* @return $this | ||
*/ | ||
public function addRange($fromValue = null, $toValue = null, ?string $key = null): self | ||
{ | ||
if (null === $fromValue && null === $toValue) { | ||
throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.'); | ||
} | ||
|
||
$range = []; | ||
|
||
if (null !== $fromValue) { | ||
$range['from'] = $fromValue; | ||
} | ||
|
||
if (null !== $toValue) { | ||
$range['to'] = $toValue; | ||
} | ||
|
||
if (null !== $key) { | ||
$range['key'] = $key; | ||
} | ||
|
||
return $this->addParam('ranges', $range); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters