antonio30111988 / evaluator
Symfony Expression Language for Laravel
1.3.3
2019-10-02 12:59 UTC
Requires
- php: >=5.4
- markrogoyski/math-php: ^0.53.0
- symfony/expression-language: ~4.4
Requires (Dev)
- mockery/mockery: ~1.0
- satooshi/php-coveralls: ~2.1
This package is auto-updated.
Last update: 2024-10-29 05:53:00 UTC
README
Symfony Expression Language module for Laravel.
Forked from https://github.com/periloso/evaluator
Installation
Simply update the composer.json
file and run composer install
.
"require": { "antonio30111988/evaluator": "1.3.*" }
Quick Installation
composer require "antonio30111988/evaluator=1.3.*"
How To Use
Evaluating an expression
$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.
Condition
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);