addgod/evaluator
Composer 安装命令:
composer require addgod/evaluator
包简介
Laravel package for symfony expression language component
README 文档
README
A Laravel package and Orchestra extension for symfony/expression-language component.
Installation
composer require addgod/evaluator
Setup
'providers' => [ Orchestra\Memory\MemoryServiceProvider::class, ];
Run migration
php artisan migrate
Adapter
This package provide Orchesta Memory as the default driver.
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);
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-12