-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from splitio/sdks-8242-semver-imp
Semver implementation
- Loading branch information
Showing
26 changed files
with
1,423 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ jobs: | |
- '8.0' | ||
- '8.1' | ||
- '8.2' | ||
- '8.3' | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
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,7 @@ | ||
<?php | ||
namespace SplitIO\Exception; | ||
|
||
class SemverParseException extends \LogicException | ||
{ | ||
|
||
} |
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,7 @@ | ||
<?php | ||
namespace SplitIO\Exception; | ||
|
||
class UnsupportedMatcherException extends \LogicException | ||
{ | ||
|
||
} |
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,48 @@ | ||
<?php | ||
namespace SplitIO\Grammar\Condition\Matcher; | ||
|
||
use SplitIO\Grammar\Condition\Matcher; | ||
use SplitIO\Grammar\Semver\Semver; | ||
use SplitIO\Grammar\Semver\SemverComparer; | ||
use SplitIO\Split as SplitApp; | ||
|
||
class BetweenSemver extends AbstractMatcher | ||
{ | ||
protected $startTarget = null; | ||
protected $endTarget = null; | ||
|
||
public function __construct($data, $negate = false, $attribute = null) | ||
{ | ||
parent::__construct(Matcher::BETWEEN_SEMVER, $negate, $attribute); | ||
|
||
if ($data != null) { | ||
$this->startTarget = Semver::build($data['start']); | ||
$this->endTarget = Semver::build($data['end']); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param mixed $key | ||
*/ | ||
protected function evalKey($key) | ||
{ | ||
if ($key == null || !is_string($key) || $this->startTarget == null || $this->endTarget == null) { | ||
return false; | ||
} | ||
|
||
$keySemver = Semver::build($key); | ||
if ($keySemver == null) { | ||
return false; | ||
} | ||
|
||
$result = SemverComparer::do($keySemver, $this->startTarget) >= 0 | ||
&& SemverComparer::do($keySemver, $this->endTarget) <= 0; | ||
|
||
SplitApp::logger()->debug($this->startTarget->getVersion() . " <= " | ||
. $keySemver->getVersion() . " <= " . $this->endTarget->getVersion() | ||
. " | Result: " . $result); | ||
|
||
return $result; | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
namespace SplitIO\Grammar\Condition\Matcher; | ||
|
||
use SplitIO\Grammar\Condition\Matcher; | ||
use SplitIO\Grammar\Semver\Semver; | ||
use SplitIO\Grammar\Semver\SemverComparer; | ||
use SplitIO\Split as SplitApp; | ||
|
||
class EqualToSemver extends AbstractMatcher | ||
{ | ||
private $toCompare; | ||
|
||
public function __construct($toCompare, $negate = false, $attribute = null) | ||
{ | ||
parent::__construct(Matcher::EQUAL_TO_SEMVER, $negate, $attribute); | ||
|
||
$this->toCompare = Semver::build($toCompare); | ||
} | ||
|
||
/** | ||
* | ||
* @param mixed $key | ||
*/ | ||
protected function evalKey($key) | ||
{ | ||
if ($key == null || $this->toCompare == null || !is_string($key)) { | ||
return false; | ||
} | ||
|
||
$keySemver = Semver::build($key); | ||
if ($keySemver == null) { | ||
return false; | ||
} | ||
|
||
$result = SemverComparer::equals($this->toCompare, $keySemver); | ||
|
||
SplitApp::logger()->debug($this->toCompare->getVersion() . " == " | ||
. $keySemver->getVersion() . " | Result: " . $result); | ||
|
||
return $result; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/SplitIO/Grammar/Condition/Matcher/GreaterThanOrEqualToSemver.php
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,42 @@ | ||
<?php | ||
namespace SplitIO\Grammar\Condition\Matcher; | ||
|
||
use SplitIO\Grammar\Condition\Matcher; | ||
use SplitIO\Grammar\Semver\Semver; | ||
use SplitIO\Grammar\Semver\SemverComparer; | ||
use SplitIO\Split as SplitApp; | ||
|
||
class GreaterThanOrEqualToSemver extends AbstractMatcher | ||
{ | ||
private $target; | ||
|
||
public function __construct($toCompare, $negate = false, $attribute = null) | ||
{ | ||
parent::__construct(Matcher::GREATER_THAN_OR_EQUAL_TO_SEMVER, $negate, $attribute); | ||
|
||
$this->target = Semver::build($toCompare); | ||
} | ||
|
||
/** | ||
* | ||
* @param mixed $key | ||
*/ | ||
protected function evalKey($key) | ||
{ | ||
if ($key == null || $this->target == null || !is_string($key)) { | ||
return false; | ||
} | ||
|
||
$keySemver = Semver::build($key); | ||
if ($keySemver == null) { | ||
return false; | ||
} | ||
|
||
$result = SemverComparer::do($keySemver, $this->target) >= 0; | ||
|
||
SplitApp::logger()->debug($this->target->getVersion() . " >= " | ||
. $keySemver->getVersion() . " | Result: " . $result); | ||
|
||
return $result; | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
namespace SplitIO\Grammar\Condition\Matcher; | ||
|
||
use SplitIO\Grammar\Condition\Matcher; | ||
use SplitIO\Grammar\Semver\Semver; | ||
use SplitIO\Grammar\Semver\SemverComparer; | ||
|
||
class InListSemver extends AbstractMatcher | ||
{ | ||
private $targetList; | ||
|
||
public function __construct($targetList, $negate = false, $attribute = null) | ||
{ | ||
$this->targetList = array(); | ||
parent::__construct(Matcher::IN_LIST_SEMVER, $negate, $attribute); | ||
|
||
if (is_array($targetList)) { | ||
foreach ($targetList as $item) { | ||
$toAdd = Semver::build($item); | ||
|
||
if ($toAdd != null) { | ||
array_push($this->targetList, $toAdd); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param mixed $key | ||
*/ | ||
protected function evalKey($key) | ||
{ | ||
if ($key == null || !is_string($key) || count($this->targetList) == 0) { | ||
return false; | ||
} | ||
|
||
$keySemver = Semver::build($key); | ||
if ($keySemver == null) { | ||
return false; | ||
} | ||
|
||
foreach ($this->targetList as $item) { | ||
if (SemverComparer::equals($keySemver, $item)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/SplitIO/Grammar/Condition/Matcher/LessThanOrEqualToSemver.php
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,42 @@ | ||
<?php | ||
namespace SplitIO\Grammar\Condition\Matcher; | ||
|
||
use SplitIO\Grammar\Condition\Matcher; | ||
use SplitIO\Grammar\Semver\Semver; | ||
use SplitIO\Grammar\Semver\SemverComparer; | ||
use SplitIO\Split as SplitApp; | ||
|
||
class LessThanOrEqualToSemver extends AbstractMatcher | ||
{ | ||
private $target; | ||
|
||
public function __construct($toCompare, $negate = false, $attribute = null) | ||
{ | ||
parent::__construct(Matcher::LESS_THAN_OR_EQUAL_TO_SEMVER, $negate, $attribute); | ||
|
||
$this->target = Semver::build($toCompare); | ||
} | ||
|
||
/** | ||
* | ||
* @param mixed $key | ||
*/ | ||
protected function evalKey($key) | ||
{ | ||
if ($key == null || $this->target == null || !is_string($key)) { | ||
return false; | ||
} | ||
|
||
$keySemver = Semver::build($key); | ||
if ($keySemver == null) { | ||
return false; | ||
} | ||
|
||
$result = SemverComparer::do($keySemver, $this->target) <= 0; | ||
|
||
SplitApp::logger()->debug($this->target->getVersion() . " <= " | ||
. $keySemver->getVersion() . " | Result: " . $result); | ||
|
||
return $result; | ||
} | ||
} |
Oops, something went wrong.