Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sokil/php-smel
Structural Matching Expression Language
https://github.com/sokil/php-smel
Last synced: 23 days ago
JSON representation
Structural Matching Expression Language
- Host: GitHub
- URL: https://github.com/sokil/php-smel
- Owner: sokil
- License: mit
- Created: 2023-04-09T08:05:14.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-04-09T09:49:28.000Z (over 1 year ago)
- Last Synced: 2024-10-09T23:03:34.219Z (about 1 month ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Structural Matching Expression Language
## Installation
### Composer
```
composer req sokil/php-smel
```## Usage
```php
evaluate(
['param' => ['eq' => 42]],
['param' => 42]
);
```## Expression language
Expression may be represented as array or JSON string:
```php
["eq" => 42]];
```Expression consists of logical and comparison operations over nodes of some key-value structure:
```php
evaluate(
// expression
[
'param1' => [
'eq' => 42,
],
'param2' => [
'eq' => 43,
]
],
// key-value structure
[
'param1' => 42,
'param2' => 43,
]
);// will return true
```Expression may be compound:
```php
evaluate(
// expression
['param' => ['gt' => 10, 'lt' => 30]],
// key-value struct
['param' => 20]
);// will return true
```## Comparison expression
| Name | Description |
|------|------------------------|
| eq | Equals |
| neq | Not equals |
| lt | Less then |
| lte | Less then or equals |
| gt | Greater then |
| gte | Greater than or equals |
| in | In array |
| nin | Not in array |### Equals
```json
{"someField": {"eq": 42}}
```or shorthand
```json
{"someField": 42}
```### Not Equals
```json
{"someField": {"neq": 42}}
```### Greater than
```json
{"someField": {"gt": 42}}
```If comparing greater or equals:
```json
{"someField": {"gte": 42}}
```### Less than
```json
{"someField": {"lt": 42}}
```If comparing less or equals:
```json
{"someField": {"lte": 42}}
```### In array
```json
{"someField": {"in": ["UKR", "USA"]}}
```### Not in array
```json
{"someField": {"nin": ["UKR", "USA"]}}
```