Package Data | |
---|---|
Maintainer Username: | periloso |
Maintainer Contact: | mail@periloso.com (Alessio Periloso) |
Package Create Date: | 2017-04-20 |
Package Last Update: | 2019-10-02 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-09-05 03:13:09 |
Package Statistics | |
---|---|
Total Downloads: | 133 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 2 |
Total Forks: | 1 |
Total Open Issues: | 0 |
Symfony Expression Language module for Laravel.
Simply update the composer.json
file and run composer install
.
"require": {
"periloso/evaluator": "1.0.*"
}
composer require "periloso/evaluator=1.0.*"
$test = [
'foo' => 10,
'bar' => 5
];
echo Evaluator::evaluate('foo > bar', $test); //this will return true
You can also save the expression rule.
$test = [
'foo' => 10,
'bar' => 5
];
Evaluator::expression()->add('test', 'foo > bar');
echo Evaluator::evaluateRule('test', $test); //this will return true
For supported expressions, visit the Symfony Expression Language Component.
Let say we want to implement 10% tax to our collection.
$item = [
'price' => 100
];
$condition = [
'target' => 'price',
'action' => '10%',
'rule' => 'price > 50'
];
Evaluator::expression()->add('tax', $condition);
$calculated = Evaluator::condition('tax', $item);
Item with multiplier.
$item = [
'price' => 50,
'quantity' => 2
];
$condition = [
'target' => 'price',
'action' => '10%',
'rule' => 'price > 50',
'multiplier' => 'quantity'
];
Evaluator::expression()->add('tax', $condition);
$calculated = Evaluator::condition('tax', $item);