nkonovski / boolean-evaluator
Build boolean expressions and apply them to stuff
dev-master / 1.0.x-dev
2018-04-03 08:21 UTC
This package is not auto-updated.
Last update: 2025-06-12 08:05:40 UTC
README
This is an experiment in PHP to build up an expression that can be evaluated in arbitrary ways. It wasn't meant for production, but if you're interested drop me a line and I'll start tagging releases.
Install
Via Composer
$ composer require davidrjonas/boolean-evaluator
Usage
<?php require __DIR__ . '/vendor/autoload.php'; use DavidRJonas\BooleanEvaluator as B; $expr = (new B\Expression) ->bAnd('A', 'B') ->bOr('C', 'D') ->bNot( (new B\Expression)->bAnd('C', 'D') ); print (new B\Evaluator\Stringer)->apply($expr); // output: A and B and (C or D) and not (C and D) $evaluator = new B\Evaluator\SetContains; var_dump($evaluator->apply($expr, ['A', 'B', 'C'])); // true var_dump($evaluator->apply($expr, ['A', 'B', 'D'])); // true var_dump($evaluator->apply($expr, ['A', 'B'])); // false, a C or D is missing var_dump($evaluator->apply($expr, ['A', 'B', 'C', 'D'])); // false, C or D but not both
License
The MIT License (MIT). Please see License File for more information.