-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,576 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
## [Unreleased] | ||
### Added | ||
- support for mongodb 3.6 | ||
|
||
## [0.0.1] - 2019-12-01 | ||
### Added | ||
- support for elasticsearch6 |
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 |
---|---|---|
@@ -1,7 +1,26 @@ | ||
Base Library for condition builders | ||
==================== | ||
|
||
[![Latest Version](https://img.shields.io/github/tag/mice-tm/yii2-condition-builder.svg?style=flat-square&label=release)](https://github.com/mice-tm/yii2-condition-builder/releases) | ||
[![Latest Version](https://img.shields.io/github/tag/mice-tm/conditions-base.svg?style=flat-square&label=release)](https://github.com/mice-tm/conditions-base/releases) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/mice-tm/yii2-condition-builder.svg?style=flat-square)](https://packagist.org/packages/mice-tm/yii2-condition-builder) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/mice-tm/conditions-base.svg?style=flat-square)](https://packagist.org/packages/mice-tm/conditions-base) | ||
|
||
This library represents flexible mechanism for building logical conditions for furser elasticsearch search query generation by this conditions. | ||
|
||
Supports ES6. | ||
|
||
|
||
Usage | ||
----- | ||
|
||
|
||
Tests | ||
----- | ||
|
||
```bash | ||
./unit.sh | ||
``` | ||
|
||
[CHANGELOG]: ./CHANGELOG.md | ||
[version-badge]: https://img.shields.io/badge/version-0.0.1-blue.svg | ||
|
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,18 @@ | ||
paths: | ||
tests: tests | ||
output: tests/_output | ||
data: tests/_data | ||
support: tests/_support | ||
envs: tests/_envs | ||
actor_suffix: Tester | ||
settings: | ||
bootstrap: ../_bootstrap.php | ||
extensions: | ||
enabled: | ||
- Codeception\Extension\RunFailed | ||
coverage: | ||
enabled: true | ||
remote: false | ||
whitelist: | ||
include: | ||
- src/services/* |
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,18 @@ | ||
<?php | ||
namespace micetm\conditionsBase\exceptions; | ||
|
||
class AttributeNotFoundException extends \Exception | ||
{ | ||
private $attribute; | ||
|
||
public function __construct($attribute, $message = "", $code = 0, Throwable $previous = null) | ||
{ | ||
$this->attribute = $attribute; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
public function getAttribute() | ||
{ | ||
return $this->attribute; | ||
} | ||
} |
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,80 @@ | ||
<?php | ||
|
||
namespace micetm\conditionsBase\models\conditions; | ||
|
||
use micetm\conditionsBase\models\ConditionInterface; | ||
use yii\base\Model; | ||
use yii2tech\embedded\ContainerInterface; | ||
use yii2tech\embedded\ContainerTrait; | ||
|
||
/** | ||
* Class Condition | ||
* @package micetm\conditionsBase\models\conditions | ||
*/ | ||
class Condition extends Model implements ContainerInterface, ConditionInterface | ||
{ | ||
use ContainerTrait; | ||
|
||
/** @var string */ | ||
public $operator; | ||
|
||
/** @var string */ | ||
public $attribute; | ||
|
||
/** @var string */ | ||
public $comparison; | ||
|
||
/** @var mixed */ | ||
public $value; | ||
|
||
public $conditions = []; | ||
|
||
public static $operators = [ | ||
self::OPERATOR_AND => self::OPERATOR_AND, | ||
self::OPERATOR_OR => self::OPERATOR_OR, | ||
self::OPERATOR_NOT => self::OPERATOR_NOT, | ||
self::OPERATOR_STATEMENT => self::OPERATOR_STATEMENT | ||
]; | ||
|
||
|
||
public function embedConditionModels() | ||
{ | ||
return $this->mapEmbeddedList('conditions', Condition::class, ['unsetSource' => false]); | ||
} | ||
|
||
public function rules() | ||
{ | ||
return [ | ||
[['operator', 'attribute', 'comparison'], 'string'], | ||
['operator', 'in', 'range' => self::$operators], | ||
// [ | ||
// ['operator'], | ||
// 'required', | ||
// 'on' => self::SCENARIO_DEFAULT | ||
// ], | ||
['conditionModels', 'yii2tech\embedded\Validator', 'message' => 'Conditions are invalid.'], | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function scenarios() | ||
{ | ||
return [ | ||
self::SCENARIO_DEFAULT => [ | ||
'operator', | ||
'attribute', | ||
'comparison', | ||
'conditionModels', | ||
'value', | ||
], | ||
] + parent::scenarios(); | ||
} | ||
|
||
public function isUnary():bool | ||
{ | ||
return !empty($this->attribute) && !empty($this->comparison); | ||
} | ||
|
||
} |
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,104 @@ | ||
<?php | ||
|
||
namespace micetm\conditionsBase\services; | ||
|
||
use micetm\conditionsBase\models\AttributeInterface; | ||
use micetm\conditionsBase\models\ConditionInterface; | ||
|
||
|
||
class ComparisonHelper | ||
{ | ||
const COMPARISONS_ASSERTS = [ | ||
AttributeInterface::EQUAL_TO_COMPARISON => 'eq', | ||
AttributeInterface::GREATER_THAN_COMPARISON => 'gt', | ||
AttributeInterface::GREATER_THAN_OR_EQUAL_TO_COMPARISON => 'gte', | ||
AttributeInterface::LESS_THAN_COMPARISON => 'lt', | ||
AttributeInterface::LESS_THAN_OR_EQUAL_TO_COMPARISON => 'lte', | ||
AttributeInterface::LIKE_COMPARISON => 'like', | ||
AttributeInterface::MORE_THAN_ONE_IN_COMPARISON => 'in', | ||
]; | ||
|
||
/** | ||
* @param Condition $condition | ||
* @param $value | ||
* @return bool | ||
*/ | ||
public static function compare(ConditionInterface $condition, $value) | ||
{ | ||
if (empty(self::COMPARISONS_ASSERTS[$condition->comparison])) { | ||
return self::in($condition->value, $value); | ||
} | ||
|
||
return self::{self::COMPARISONS_ASSERTS[$condition->comparison]}($condition->value, $value); | ||
} | ||
|
||
/** | ||
* @param mixed $a | ||
* @param mixed $b | ||
* @return bool | ||
*/ | ||
public static function in($a, $b) | ||
{ | ||
return !empty(array_intersect((array)$a, (array)$b)); | ||
} | ||
|
||
/** | ||
* @param mixed $a | ||
* @param mixed $b | ||
* @return bool | ||
*/ | ||
public static function eq($a, $b) | ||
{ | ||
return $a == $b; | ||
} | ||
|
||
/** | ||
* @param mixed $a | ||
* @param mixed $b | ||
* @return bool | ||
*/ | ||
public static function gt($a, $b) | ||
{ | ||
return $a > $b; | ||
} | ||
|
||
/** | ||
* @param mixed $a | ||
* @param mixed $b | ||
* @return bool | ||
*/ | ||
public static function gte($a, $b) | ||
{ | ||
return $a >= $b; | ||
} | ||
|
||
/** | ||
* @param mixed $a | ||
* @param mixed $b | ||
* @return bool | ||
*/ | ||
public static function lt($a, $b) | ||
{ | ||
return $a < $b; | ||
} | ||
|
||
/** | ||
* @param mixed $a | ||
* @param mixed $b | ||
* @return bool | ||
*/ | ||
public static function lte($a, $b) | ||
{ | ||
return $a <= $b; | ||
} | ||
|
||
/** | ||
* @param mixed $a | ||
* @param mixed $b | ||
* @return bool | ||
*/ | ||
public static function like($a, $b) | ||
{ | ||
return false !== strpos($b, $a); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
namespace micetm\conditionsBase\services; | ||
|
||
use micetm\conditionsBase\exceptions\WrongComparison; | ||
use micetm\conditionsBase\models\ComparisonInterface; | ||
use micetm\conditionsBase\models\ConditionInterface; | ||
|
||
interface ComparisonManagerInterface | ||
{ | ||
/** | ||
* @param Condition $condition | ||
* @return ComparisonInterface | ||
* @throws WrongComparison | ||
*/ | ||
public function getComparison(ConditionInterface $condition): ComparisonInterface; | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace micetm\conditionsBase\services; | ||
|
||
use micetm\conditionsBase\models\conditions\Condition; | ||
|
||
interface OracleInterface | ||
{ | ||
/** | ||
* @param Condition $condition Consists of attribute name, its value and a comparison type | ||
* @param array|object $target Where to find coresponding attribute value for comparison | ||
* @return bool | ||
*/ | ||
public function speak(Condition $condition, $target): bool; | ||
} |
Oops, something went wrong.