All Projects → subzeta → ruling

subzeta / ruling

Licence: other
Stateless rule engine

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to ruling

Wongi Engine
A rule engine written in Ruby.
Stars: ✭ 414 (+2078.95%)
Mutual labels:  rule-engine
Iotplatform
An open-source IoT platform that enables rapid development, management and scaling of IoT projects. With this IoT platform, you are able to: 1) Provision and control devices, 2) Collect and visualize data from devices, 3) Analyze device data and trigger alarms, 4) Deliver device data to other systems, 5) Enable use-case specific features using customizable rules and plugins.
Stars: ✭ 82 (+331.58%)
Mutual labels:  rule-engine
Kogito Runtimes
Kogito Runtimes - Kogito is a cloud-native business automation technology for building cloud-ready business applications.
Stars: ✭ 188 (+889.47%)
Mutual labels:  rule-engine
Ruler
The Hoa\Ruler library.
Stars: ✭ 612 (+3121.05%)
Mutual labels:  rule-engine
Json Rules Engine
A rules engine expressed in JSON
Stars: ✭ 1,159 (+6000%)
Mutual labels:  rule-engine
Psrule
Validate infrastructure as code (IaC) and objects using PowerShell rules.
Stars: ✭ 107 (+463.16%)
Mutual labels:  rule-engine
Drools
Drools is a rule engine, DMN engine and complex event processing (CEP) engine for Java.
Stars: ✭ 4,062 (+21278.95%)
Mutual labels:  rule-engine
WHMCS-JSJ-API-Pay-Gateway
WHMCS 财务系统对接金莎云免签支付API(你们怎么用,与我无瓜好吧:)
Stars: ✭ 58 (+205.26%)
Mutual labels:  callback
G Rule
Groovy based lightweight rule engine
Stars: ✭ 76 (+300%)
Mutual labels:  rule-engine
Mon Entreprise
L'assistant officiel de l'entrepreneur
Stars: ✭ 123 (+547.37%)
Mutual labels:  rule-engine
Grule Rule Engine
Rule engine implementation in Golang
Stars: ✭ 729 (+3736.84%)
Mutual labels:  rule-engine
Nrules
Rules engine for .NET, based on the Rete matching algorithm, with internal DSL in C#.
Stars: ✭ 1,003 (+5178.95%)
Mutual labels:  rule-engine
Iot Technical Guide
🐝 IoT Technical Guide --- 从零搭建高性能物联网平台及物联网解决方案和Thingsboard源码分析 ✨ ✨ ✨ (IoT Platform, SaaS, MQTT, CoAP, HTTP, Modbus, OPC, WebSocket, 物模型,Protobuf, PostgreSQL, MongoDB, Spring Security, OAuth2, RuleEngine, Kafka, Docker)
Stars: ✭ 2,334 (+12184.21%)
Mutual labels:  rule-engine
Node Rules
Node-rules is a light weight forward chaining rule engine written in JavaScript.
Stars: ✭ 481 (+2431.58%)
Mutual labels:  rule-engine
Yql
yet another query language for rule engine in golang
Stars: ✭ 215 (+1031.58%)
Mutual labels:  rule-engine
Jetlinks
JetLinks Core
Stars: ✭ 380 (+1900%)
Mutual labels:  rule-engine
Jetlinks Community
JetLinks 基于Java8,Spring Boot 2.x ,WebFlux,Netty,Vert.x,Reactor等开发, 是一个全响应式的企业级物联网平台。支持统一物模型管理,多种设备,多种厂家,统一管理。统一设备连接管理,多协议适配(TCP,MQTT,UDP,CoAP,HTTP等),屏蔽网络编程复杂性,灵活接入不同厂家不同协议等设备。实时数据处理,设备告警,消息通知,数据转发。地理位置,数据可视化等。能帮助你快速建立物联网相关业务系统。
Stars: ✭ 2,405 (+12557.89%)
Mutual labels:  rule-engine
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (+73.68%)
Mutual labels:  assert
ekuiper
Lightweight data stream processing engine for IoT edge
Stars: ✭ 975 (+5031.58%)
Mutual labels:  rule-engine
Dry Logic
Predicate logic with rule composition
Stars: ✭ 118 (+521.05%)
Mutual labels:  rule-engine

Rule engine

Stateless rule engine to assert statements given a context.

Install

$ composer require "subzeta/ruling" : "^2.0"

Usage example

require '/path/to/vendor/autoload.php';

use subzeta\Ruling\Ruling;

$my = new \stdClass();
$my->sensitivity = 80;
$my->joyfulness = 10;

(new Ruling())
    ->given([
        'sensitivity' => $my->sensitivity,
        'joyfulness' => $my->joyfulness
    ])->when(
        ':sensitivity is greater than 90 or :joyfulness is less than 20'
    )->then(function() {
        echo 'Hell yeah, I should listen music right now!';
    })->otherwise(function() {
        echo 'I\'m happy enough, thanks.';
    })->execute();

// Outputs: Hell yeah, I should listen music right now!

Calls

There are three main entrances:

interpret

Returns the interpreted rules. Using the example above the output would be: ['80 > 90 || 10 < 20']

assert

Returns a boolean indicating the output. Using the example above the output would be: true

execute

Fires the success or fail callback if defined. Using the example above the output would be: 'Hell yeah, I should listen it!'

Error handling

Different types of exceptions are thrown when something goes wrong:

InvalidContextException

When the provided context isn't valid (accepts: ['string-key-1' => value-1, ..., 'string-key-x' => value-x]).

InvalidRuleException

When the provided rules aren't valid (accepts: 'string' or ['string-1', ..., 'string-x'])

InvalidCallbackException

When the provided success/fail callback isn't callable (accepts: function(){return 'Hey Ho! Let's go!';})

Supported Operators

Type Operator Representation
Comparison is greater than >
Comparison is greater or equal to >=
Comparison is less than <
Comparison is less or equal to <=
Comparison is equal to (alias: is) ==
Comparison is not equal to (aliases: is not, isn't) !=
Comparison same as ===
Comparison not same as !==
Logical and &&
Logical or ||
Containment contained in (alias: in) in

Notes

  • It's not necessary to provide callbacks for execute method, it will return a boolean instead as assert does.
  • Rules respect the operator precedence and evaluate the parenthesis from right to left.

Testing

$ phpunit

Recursive to do list

  • Increase the number of unit tests to prevent bad contexts or bad formatted rules from being executed.

To do

  • Improve the interpreted method response.

Changelist

  • Allow aliases ("is equal to" can be written as "is" and "is not equal to" as "is not"/"isn't").
  • Context values may permit callable functions too.
  • Added the strict comparison operators (same as, not same as).
  • It can be interesting to implement a kind of dump method to show the interpreted rule.
  • Added the "in" operator.
  • Context accepts array values.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].