-
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.
Merge pull request #7 from ibrahimgunduz34/regex_operator
Regex operator
- Loading branch information
Showing
7 changed files
with
219 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
namespace SweetCode\MariaBundle\Operator; | ||
|
||
class RegexOperator extends Operator | ||
{ | ||
/** | ||
* @param array $data | ||
* @return bool | ||
*/ | ||
protected function accept($data) | ||
{ | ||
$field = $this->getField(); | ||
if (!array_key_exists($field, $data)) { | ||
return false; | ||
} | ||
|
||
return boolval(preg_match($this->getValue(), $data[$field])); | ||
} | ||
} |
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,66 @@ | ||
## Iterable Matchers | ||
|
||
[Back to home page](/README.md) | ||
|
||
### ALL: | ||
```yaml | ||
# ... | ||
rules: | ||
all: | ||
- amount: { gt: 100 } | ||
# ... | ||
``` | ||
|
||
### ANY: | ||
```yaml | ||
# ... | ||
rules: | ||
any: | ||
- amount: { gt: 100 } | ||
# ... | ||
``` | ||
|
||
### NONE: | ||
```yaml | ||
# ... | ||
rules: | ||
none: | ||
- amount: { gt: 100 } | ||
# ... | ||
``` | ||
|
||
### FIRST: | ||
```yaml | ||
# ... | ||
rules: | ||
first: | ||
- amount: { gt: 100 } | ||
# ... | ||
``` | ||
|
||
### LAST: | ||
```yaml | ||
# ... | ||
rules: | ||
last: | ||
- amount: { gt: 100 } | ||
# ... | ||
``` | ||
|
||
### DEFAULT: | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
- amount: { gt: 100 } | ||
# ... | ||
``` | ||
or | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
default: | ||
- amount: { gt: 100 } | ||
# ... | ||
``` |
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,92 @@ | ||
## Arithmetic And Logic Operators | ||
|
||
[Back to home page](/README.md) | ||
|
||
### Greater Than X | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
- amount: { gt: 100 } | ||
# ... | ||
``` | ||
|
||
### Less Than X | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
- amount: { lt: 100 } | ||
# ... | ||
``` | ||
|
||
### Greater Than Or EqualX | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
- amount: { gte: 100 } | ||
# ... | ||
``` | ||
|
||
### Less Than Or Equal X | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
- amount: { lte: 100 } | ||
# ... | ||
``` | ||
|
||
### Between | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
- amount: { btw: [100, 500] } | ||
# ... | ||
``` | ||
|
||
### Regex | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
- description: { regex: /awesome/i } | ||
# ... | ||
``` | ||
|
||
### In [...] | ||
```yaml | ||
# ... | ||
rules: | ||
- category_id: { in: [1,2,3] } | ||
# ... | ||
``` | ||
### And | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
- amount: { gt: 100 } | ||
category_id: { in: [1,2,3] } | ||
# ... | ||
``` | ||
|
||
### Or | ||
|
||
```yaml | ||
# ... | ||
rules: | ||
- category_id: { eql: 10 } | ||
- category_id: { eql: 5 } | ||
# ... | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,25 @@ | ||
<?php | ||
|
||
namespace SweetCode\MariaBundle\Tests\Operator; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SweetCode\MariaBundle\Operator\RegexOperator; | ||
|
||
class RegexOperatorTest extends TestCase | ||
{ | ||
public function testCompareSuccess() | ||
{ | ||
$operatorObject = new RegexOperator('field', "/gunduz/i"); | ||
|
||
$data = ['field' => 'Ibrahim Gunduz is a developer']; | ||
$this->assertTrue($operatorObject->compare($data)); | ||
} | ||
|
||
public function testCompareFail() | ||
{ | ||
$operatorObject = new RegexOperator('field', "/manager/i"); | ||
|
||
$data = ['field' => 'Ibrahim Gunduz is a developer']; | ||
$this->assertFalse($operatorObject->compare($data)); | ||
} | ||
} |