Skip to content

nkonovski/boolean-evaluator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boolean Evaluator

Software License

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.

About

Build boolean expressions in PHP and apply them to stuff

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • PHP 100.0%