PHPackages                             tankfairies/rulesengine - 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. tankfairies/rulesengine

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

tankfairies/rulesengine
=======================

High speed rules engine

2.1(2y ago)09461[1 PRs](https://github.com/tankfairies/rulesengine/pulls)MITPHPPHP ^8.2

Since May 25Pushed 1y agoCompare

[ Source](https://github.com/tankfairies/rulesengine)[ Packagist](https://packagist.org/packages/tankfairies/rulesengine)[ RSS](/packages/tankfairies-rulesengine/feed)WikiDiscussions 2.0 Synced 3d ago

READMEChangelog (9)Dependencies (4)Versions (13)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/15c5a81ae41aab0493266284763aa79b9acf5326cb49eed2885a869b589869c2/68747470733a2f2f706f7365722e707567782e6f72672f74616e6b666169726965732f72756c6573656e67696e652f762f737461626c65)](https://packagist.org/packages/tankfairies/rulesengine)[![Total Downloads](https://camo.githubusercontent.com/cb94324a5971fe7fbed7088a2a1eacdfcd6bacb4ca9825423b20a02fef5ca55e/68747470733a2f2f706f7365722e707567782e6f72672f74616e6b666169726965732f72756c6573656e67696e652f646f776e6c6f616473)](https://packagist.org/packages/tankfairies/rulesengine)[![Latest Unstable Version](https://camo.githubusercontent.com/80ef89d1ce3d2889d560df709d3c8715aed0ea5d1bad895092534c4228e1df66/68747470733a2f2f706f7365722e707567782e6f72672f74616e6b666169726965732f72756c6573656e67696e652f762f756e737461626c65)](https://packagist.org/packages/tankfairies/rulesengine)[![License](https://camo.githubusercontent.com/bd442256f12c2b9990c5180c2b202347e60a27b2fba4a0941a9669216d73c1e7/68747470733a2f2f706f7365722e707567782e6f72672f74616e6b666169726965732f72756c6573656e67696e652f6c6963656e7365)](https://packagist.org/packages/tankfairies/rulesengine)[![Build Status](https://camo.githubusercontent.com/02c1829a7ef93ed084911591e61f492743c74519c2efb9815e87c16fad5ea45f/68747470733a2f2f6170702e7472617669732d63692e636f6d2f74616e6b666169726965732f72756c6573656e67696e652e7376673f746f6b656e3d4647786645576163356d4e6267464c376d385550266272616e63683d322e30)](https://app.travis-ci.com/tankfairies/rulesengine)

Rulesengine
===========

[](#rulesengine)

Converts conditional statements into optimised asset rules. This gives the ability to store rules in files or databases.

**It is important that rules are correctly validated if the rules can be user defined.**

**This is because the rules are converted into code to make them fast**

This is supported and looked after, if there's and functionality you'd like to see; let me know and I'll look into it.

Installation
------------

[](#installation)

Install with [Composer](https://getcomposer.org/):

```
composer require tankfairies/rulesengine
```

Performance
-----------

[](#performance)

These tests were run on an Mac M1 Max with 32GB.

Running 100,000 executions 5 times: -

```
1 => 1.0200 seconds
2 => 1.0146 seconds
3 => 1.0219 seconds
4 => 1.0226 seconds
5 => 1.0206 seconds

```

Performance increases once the rule has been built: -

```
1 => 1.0178 seconds
2 => 1.0135 seconds
3 => 1.0180 seconds
4 => 1.0110 seconds
5 => 1.0097 seconds

```

On Average that's ~100000 calls per second. Performance testing was done with - `tankfairies/benchmark`

Usage
-----

[](#usage)

Instantiate a new instance of the library:

```
use Tankfairies\Rulesengine\RulesEngine;

$this->rulesEngine = new RulesEngine('storage/rules');
$rulesEngine->setRule('var == 21');
$result = $rulesEngine->evaluate(['var' => 21]);
```

The following operators are available to use in rules: -

- AND
- OR
- XOR

The following conditions are available to use in rules: -

- ==
- !-
- &lt;=
- &gt;=
- &lt;
- &gt;
- IN
- !IN

Sample Rules
------------

[](#sample-rules)

```
var == val OR var == 22
['var' => 20, 'val' => 20]
```

```
var !IN val
['var' => 20, 'val' => [21, 22, 23]]
```

```
var IN val AND var2 == "yes"
['var' => 22, 'val' => [21, 22, 23], 'var2' => 'yes']
```

```
var == 100 XOR group IN [123456, 456456]
['var' => '100', 'group' => 12121]
```

Copyright and license
---------------------

[](#copyright-and-license)

The tankfairies/rulesengine library is Copyright (c) 2019 Tankfairies () and licensed for use under the MIT License (MIT).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~197 days

Recently: every ~232 days

Total

11

Last Release

571d ago

Major Versions

v1.7 → 2.0.02024-02-14

PHP version history (2 changes)v1.0PHP ^7.1

2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/761e80f0c4632541e235d7d45128d65ace90c65e3c799c11c36a120155eaad58?d=identicon)[tankfairies](/maintainers/tankfairies)

---

Top Contributors

[![tankfairies](https://avatars.githubusercontent.com/u/50480804?v=4)](https://github.com/tankfairies "tankfairies (25 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

---

Tags

expressionrule-enginerulesenginerule parser

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/tankfairies-rulesengine/health.svg)

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

###  Alternatives

[spatie/regex

A sane interface for php's built in preg\_\* functions

1.1k17.1M59](/packages/spatie-regex)[lorisleiva/cron-translator

Makes CRON expressions human-readable

3148.5M31](/packages/lorisleiva-cron-translator)[uuf6429/rune

PHP Rule Engine.

7011.8k](/packages/uuf6429-rune)[subzeta/ruling

An stateless rule engine

2011.9k](/packages/subzeta-ruling)

PHPackages © 2026

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