Skip to content

Commit

Permalink
В фильтрах добавлена поддержка оператора in
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Aug 29, 2017
1 parent 33d98cb commit fbf303b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public static function toArray(array $filter = [])
return false;
}
break;

case 'in':
return in_array($item[$key], $value, true);
break;
}
} else {
$value = $filterItem;
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,18 @@ Status::isValid('publish', [['<', 'priority', 5]]); // false
]
```

Поддерживаемые операторы: `=`, `!=`, `>`, `<`, `>=`, `<=`.
Поддерживаемые операторы: `=`, `!=`, `>`, `<`, `>=`, `<=`, `in`.

### Оператор `in`

Проверяет, что значение соответствует одному из значений, указанных в массиве `$value`. Например:

```php
[
Status::isValid('publish', [['in', 'priority', [5, 10]]]);
Status::isValid('closed', [['in', 'value', ['publish', 'closed', 'draft']]]);
]
```

## <a name="getters"></a>Геттеры

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vjik/php-enum",
"description": "PHP 5.4+ Enum implementation",
"version": "1.1.1",
"version": "1.2.0",
"type": "library",
"keywords": [
"php",
Expand Down
3 changes: 3 additions & 0 deletions tests/WithDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public function filterProvider()
[[['>=', 'number', 101], ['<', 'number', 103]], [1, 2, 10]],
[['number' => 101, 'value' => 1], [1]],
[['number' => 13], []],
[[['in', 'number', [101, 102]]], [1, 2, 10]],
[[['in', 'value', [2, 3]]], [2, 3]],
[[['in', 'number', [1, 2]]], []],
];
}

Expand Down

0 comments on commit fbf303b

Please sign in to comment.