PHPackages                             subzeta/ruling - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. subzeta/ruling

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

subzeta/ruling
==============

An stateless rule engine

v2.1(8y ago)2011.9k↓50%2MITPHPPHP &gt;=7.1

Since Jan 24Pushed 8y ago1 watchersCompare

[ Source](https://github.com/subzeta/ruling)[ Packagist](https://packagist.org/packages/subzeta/ruling)[ Docs](https://github.com/subzeta/ruling)[ RSS](/packages/subzeta-ruling/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Rule engine
===========

[](#rule-engine)

Stateless rule engine to assert statements given a context.

Install
=======

[](#install)

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

Usage example
=============

[](#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
=====

[](#calls)

There are three main entrances:

#### interpret

[](#interpret)

Returns the interpreted rules. Using the example above the output would be: \['80 &gt; 90 || 10 &lt; 20'\]

#### assert

[](#assert)

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

#### execute

[](#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
==============

[](#error-handling)

Different types of exceptions are thrown when something goes wrong:

#### InvalidContextException

[](#invalidcontextexception)

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

#### InvalidRuleException

[](#invalidruleexception)

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

#### InvalidCallbackException

[](#invalidcallbackexception)

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

Supported Operators
===================

[](#supported-operators)

TypeOperatorRepresentationComparisonis greater than&gt;Comparisonis greater or equal to&gt;=Comparisonis less than&lt;Comparisonis less or equal to&lt;=Comparisonis equal to (alias: is)==Comparisonis not equal to (aliases: is not, isn't)!=Comparisonsame as===Comparisonnot same as!==Logicaland&amp;&amp;Logicalor||Containmentcontained in (alias: in)inNotes
=====

[](#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
=======

[](#testing)

```
$ phpunit
```

Recursive to do list
====================

[](#recursive-to-do-list)

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

To do
=====

[](#to-do)

- Improve the interpreted method response.

Changelist
==========

[](#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
=======

[](#license)

MIT

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~227 days

Total

4

Last Release

3084d ago

Major Versions

v1.1.0 → v2.02017-12-07

PHP version history (2 changes)v1.0.0PHP &gt;=5.4

v2.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/e5749063614a6daa56a17fc6540b3082020298ef9f8da93c2af05e24018e2e67?d=identicon)[subzeta](/maintainers/subzeta)

---

Top Contributors

[![subzeta](https://avatars.githubusercontent.com/u/2686117?v=4)](https://github.com/subzeta "subzeta (19 commits)")

---

Tags

assertcallbackinterpreted-rulesrule-enginerules-processorstateless-rule-engineassertrulerulerenginerule-enginerulingrule eval

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/subzeta-ruling/health.svg)

```
[![Health](https://phpackages.com/badges/subzeta-ruling/health.svg)](https://phpackages.com/packages/subzeta-ruling)
```

###  Alternatives

[pinkary-project/type-guard

Type Guard module is part of the Pinkary Project, and allows you to \*\*narrow down the type\*\* of a variable to a more specific type.

198102.4k14](/packages/pinkary-project-type-guard)[uuf6429/rune

PHP Rule Engine.

7011.8k](/packages/uuf6429-rune)[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
