PHPackages                             uuf6429/rune - 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. uuf6429/rune

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

uuf6429/rune
============

PHP Rule Engine.

2.0.0(9y ago)7011.8k19[7 issues](https://github.com/uuf6429/rune/issues)MITPHPPHP &gt;=5.5.9CI failing

Since Jul 12Pushed 2y ago11 watchersCompare

[ Source](https://github.com/uuf6429/rune)[ Packagist](https://packagist.org/packages/uuf6429/rune)[ Docs](http://github.com/uuf6429/rune)[ RSS](/packages/uuf6429-rune/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (4)Dependencies (4)Versions (10)Used By (0)

ᚱᚢᚾᛖ
====

[](#ᚱᚢᚾᛖ)

[![Build Status](https://github.com/uuf6429/rune/actions/workflows/ci.yml/badge.svg)](https://github.com/uuf6429/rune/actions)[![Latest Stable Version](https://camo.githubusercontent.com/18e34aeb120b1f5579fc02eb9db75143be7a1119c7b2caf0c78fae214c660b03/68747470733a2f2f706f7365722e707567782e6f72672f757566363432392f72756e652f76657273696f6e2e737667)](https://packagist.org/packages/uuf6429/rune)[![Latest Unstable Version](https://camo.githubusercontent.com/e0eea474bd68f822cbd27f724edb2edb47c9e6eba3365dc844ef6b7174b39491/68747470733a2f2f706f7365722e707567782e6f72672f757566363432392f72756e652f762f756e737461626c652e737667)](https://packagist.org/packages/uuf6429/rune)[![PHP Version Require](https://camo.githubusercontent.com/4afa24a71aaed9c8bb6c37745da2c6120a79cd6b0a0241ebaeb41e70fba43e59/687474703a2f2f706f7365722e707567782e6f72672f757566363432392f72756e652f726571756972652f706870)](https://www.php.net/supported-versions.php)[![License](https://camo.githubusercontent.com/2bdbb5cf3dcfdef13e95bc95b6dfdf5ab302002305790c624b3e7db4214c3fb7/68747470733a2f2f706f7365722e707567782e6f72672f757566363432392f72756e652f6c6963656e73652e737667)](https://raw.githubusercontent.com/uuf6429/rune/master/LICENSE)[![Coverage](https://camo.githubusercontent.com/5914e28debc9ae4e305abb7186da65b46959a19e116fddd2a298f5ea57ccc902/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d757566363432395f72756e65266d65747269633d636f766572616765)](https://sonarcloud.io/summary/new_code?id=uuf6429_rune)[![Reliability Rating](https://camo.githubusercontent.com/9b1850f773caf291e1de12931c2c98c2ff0ab4a80eb32a1f11cae4651f249fd9/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d757566363432395f72756e65266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/summary/new_code?id=uuf6429_rune)

Rune - A PHP **Ru**le Engi**ne** Toolkit.

This library is an implementation of a [Business Rule Engine](https://en.wikipedia.org/wiki/Business_rules_engine) (a type of Business Process Automation software).

Table Of Contents
-----------------

[](#table-of-contents)

- [ᚱᚢᚾᛖ](#%E1%9A%B1%E1%9A%A2%E1%9A%BE%E1%9B%96)
    - [Table Of Contents](#table-of-contents)
    - [Installation](#installation)
    - [Architecture](#architecture)
    - [Usage](#usage)
        - [Live Example](#live-example)
        - [Example Code](#example-code)

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

[](#installation)

The recommended and easiest way to install Rune is through [Composer](https://getcomposer.org/):

```
composer require uuf6429/rune
```

Architecture
------------

[](#architecture)

The library is made up of the following main parts:

- **Rule** (impl. [`Rule\RuleInterface`](src/Rule/RuleInterface.php)) - object representing a business rule. For most use-cases, one can just use [`Rule\GenericRule`](src/Rule/GenericRule.php). Each rule must have a unique id, descriptive name, a condition (as an expression that returns `true` or `false`) and the action (see below) to be triggered when the condition is met.
- **Action** (impl. [`Action\ActionInterface`](src/Action/ActionInterface.php)) - an object that does something when the associated rule is triggered. Actions in general can be reused by multiple rules. For example, if you're using the rule engine in product sales, an action might automatically add a fee to the bill when a certain condition applies (e.g. a fee for specific delivery countries, or a negative fee for a discount).
- **Context** (impl. [`Context\ContextInterface`](src/Context/ContextInterface.php)) - an object that provides data to the rule engine and action to work with. This can be thought of as a collection of all the available data for the current situation. For example, when the current situation is about a user buying a product, you would have data about the user, the product, offers, and perhaps also higher level information such as time, locality etc. You almost always have to implement your own context since this always depends on your (business) scenario.
- **RuleEngine** - essentially, the object that connects the others together to function.

 ```
flowchart LR
    A("
Rules
Rule 1:
- Condition: product.color == #quot;green#quot;
- Action: applyDiscount(10)

Rule 2:
- Condition: product.color == #quot;red#quot;
- Action: applyDiscount(20)
    ") --> C

    B("
Context{
    product: {
        name: #quot;Scarf#quot;,
        color: #quot;red#quot;
    }
}
    ") --> C

    subgraph RuleEngine ["Rule Engine"]
        C{"Filter Rules"} --> D(["Execute Action(s)"])
    end

    D --> E("applyDiscount(20)")

style A text-align: left
style B text-align: left
```

      Loading Usage
-----

[](#usage)

Various examples can be found in [uuf6429/rune-examples](https://github.com/uuf6429/rune-examples).

### Live Example

[](#live-example)

[   ![Try it out](https://camo.githubusercontent.com/d4e21b75216a97aa0a665744d510b5f8ee58f94ecc7fcd70b0511066461d0a3f/68747470733a2f2f757566363432392e6769746875622e696f2f72756e652d6578616d706c65732f73686f702f73637265656e73686f742d6c696768742e706e67) ](https://uuf6429.github.io/rune-examples/shop/)### Example Code

[](#example-code)

The following code is a very simple example of how Rune can be used. It defines one model (`Product`), context (`ProductContext`) and uses [`CallbackAction`](src/Action/CallbackAction.php) to print out the rules that have been triggered.

```
namespace MyApplication;

use uuf6429\Rune\Action\CallbackAction;
use uuf6429\Rune\Context\ClassContext;
use uuf6429\Rune\Engine;
use uuf6429\Rune\Rule\GenericRule;
use uuf6429\Rune\Rule\RuleInterface;

// A class whose instances will be available inside the rule engine.
class Product
{
    public function __construct(
        public readonly string $name,
        public readonly string $colour,
    ) {
    }
}

// A class that represents the rule engine execution context.
// Note that public properties will be available in the rule expressions,
// in this case rules will have access to "product" as a variable (and all of product's public properties).
class ProductContext extends ClassContext
{
    public function __construct(
        public readonly Product $product
    ) {
    }
}

// Declare an action to be triggered when a rule matches against a product.
$action = new CallbackAction(
    static fn ($eval, ProductContext $context, RuleInterface $rule) => printf(
        "Rule %s triggered for %s %s\n",
        $rule->getId(),
        ucwords($context->product->colour),
        $context->product->name
    )
);

// Declare some sample rules.
$rules = [
    new GenericRule(1, 'Red Products', 'product.colour == "red"', $action),
    new GenericRule(2, 'Red Socks', 'product.colour == "red" and product.name matches "/socks/i"', $action),
    new GenericRule(3, 'Green Socks', 'product.colour == "green" and product.name matches "/socks/i"', $action),
    new GenericRule(4, 'Socks', 'product.name matches "/socks/" > 0', $action),
];

// Declare available products (to run rules against).
$products = [
    new Product('Bricks', 'red'),
    new Product('Soft Socks', 'green'),
    new Product('Sporty Socks', 'yellow'),
];

// Create rule engine.
$engine = new Engine();

// Run rules for each product. Note that each product should exist in a separate context.
foreach ($products as $product) {
    $engine->execute(new ProductContext($product), $rules);
}
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

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 ~532 days

Recently: every ~659 days

Total

6

Last Release

975d ago

Major Versions

1.1 → 2.0.02016-08-09

2.x-dev → 3.x-dev2020-08-09

PHP version history (4 changes)1.0.0PHP &gt;=5.5.9

2.x-devPHP &gt;=5.6

3.x-devPHP ^7.2

3.0-RC1PHP ^7.4 || ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/450767af6ef832ad662c169bf718d6d25c025c08b2d91b810959d190bccebba1?d=identicon)[uuf6429](/maintainers/uuf6429)

---

Top Contributors

[![uuf6429](https://avatars.githubusercontent.com/u/230049?v=4)](https://github.com/uuf6429 "uuf6429 (93 commits)")

---

Tags

businessenginephp-libraryruleexpressionruleengineuuf6429

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/uuf6429-rune/health.svg)

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

###  Alternatives

[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1175.2k](/packages/rcsofttech-audit-trail-bundle)[verbb/formie

The most user-friendly forms plugin for Craft.

100387.6k58](/packages/verbb-formie)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

53675.5k16](/packages/solspace-craft-freeform)[typo3/cms-form

TYPO3 CMS Form - Flexible TYPO3 frontend form framework that comes with a backend editor interface.

147.4M240](/packages/typo3-cms-form)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3691.3k16](/packages/netgen-layouts-core)[subzeta/ruling

An stateless rule engine

1912.1k](/packages/subzeta-ruling)

PHPackages © 2026

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