New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

periloso/evaluator

Symfony Expression Language for Laravel
164 3
Install
composer require periloso/evaluator
Latest Version:1.3.1
PHP:>=5.4
License:MIT
Last Updated:Oct 2, 2019
Links: GitHub  ·  Packagist
Maintainer: periloso

Evaluator

Symfony Expression Language module for Laravel.

Installation

Simply update the composer.json file and run composer install.

"require": {
	"periloso/evaluator": "1.0.*"
}

Quick Installation

composer require "periloso/evaluator=1.0.*"

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);

Related Packages

fruitcake/php-cors

Cross-origin resource sharing library for the Symfony HttpFoundation

331,211,453 317
franzose/kontrolio

Simple and standalone data validation library inspired by Laravel and Symfony

986 49
elepunk/evaluator

Laravel package for symfony expression language component

192 9
vilnius-technology/symfonys-facade

Symfonys facade for The Laravel Framework.

75 1
arifmahmudrana/context

PHP single context. Key value store in current context.

24 4

Version History

Version Released PHP License
1.3.1 >=5.4 MIT
1.3.0 >=5.4 MIT