Package Data | |
---|---|
Maintainer Username: | shopalicious |
Maintainer Contact: | ahmadshahhafizan@gmail.com (Ahmad Shah Hafizan Hamidin) |
Package Create Date: | 2014-09-23 |
Package Last Update: | 2015-02-24 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-10 15:05:04 |
Package Statistics | |
---|---|
Total Downloads: | 190 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 9 |
Total Watchers: | 2 |
Total Forks: | 1 |
Total Open Issues: | 0 |
A Laravel package and Orchestra extension for symfony/expression-language component.
Simpy update the composer.json
file and run composer install
.
"require": {
"elepunk/evaluator": "1.0.*"
}
composer require "elepunk/evaluator=1.0.*"
If you are using Orchestra Platform, you can simply enable the extension or add the service provider. This will also load the Evaluator
alias automatically.
'providers' => [
'Elepunk\Evaluator\EvaluatorServiceProvider'
];
This package provide Orchesta Memory as the default driver.
$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);