PHPackages                             indigophp/ruler - 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. indigophp/ruler

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

indigophp/ruler
===============

Library for being able to define logical rules and conditional outcomes

v0.2(11y ago)223[1 issues](https://github.com/indigophp/ruler/issues)MITPHPPHP &gt;=5.4

Since Oct 7Pushed 11y ago1 watchersCompare

[ Source](https://github.com/indigophp/ruler)[ Packagist](https://packagist.org/packages/indigophp/ruler)[ RSS](/packages/indigophp-ruler/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (3)Used By (0)

Indigo Ruler
============

[](#indigo-ruler)

[![Latest Version](https://camo.githubusercontent.com/6e1387441f1e4b9ed3a7e591a46ab3c90ed20b3994de787feded6a449df76a87/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f696e6469676f7068702f72756c65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/indigophp/ruler/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/f728999b162d6373928831610fe7d43f97cab48bfee35dfcc8c836f4ca74ae9e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f696e6469676f7068702f72756c65722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/indigophp/ruler)[![Code Coverage](https://camo.githubusercontent.com/52afd5b3c0df7a21e3517016dc0619a6898972e9cf4b252a8959a1d3bc07ff64/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f696e6469676f7068702f72756c65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/indigophp/ruler)[![Quality Score](https://camo.githubusercontent.com/39272159224eed9ae37af9a07bfb563f87490396c54ce85673df9c3256519603/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f696e6469676f7068702f72756c65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/indigophp/ruler)[![HHVM Status](https://camo.githubusercontent.com/ee68219031a7c0d32be4d17743c14235d29c2ed0645e24b0385ce2b61708a4e3/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f696e6469676f7068702f72756c65722e7376673f7374796c653d666c61742d737175617265)](http://hhvm.h4cc.de/package/indigophp/ruler)[![Total Downloads](https://camo.githubusercontent.com/5e59e3cf05371969378eca93029140b0a229564db4dc04f5cbf9807bd64eb59b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e6469676f7068702f72756c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/indigophp/ruler)[![Dependency Status](https://camo.githubusercontent.com/873e9a92f5e90ae526f93dc07fb2befd55f8133d8265594f39823db422618983/68747470733a2f2f696d672e736869656c64732e696f2f76657273696f6e6579652f642f7068702f696e6469676f7068703a636172742e7376673f7374796c653d666c61742d737175617265)](https://www.versioneye.com/php/indigophp:cart)

**Library to process logical rules and apply outcomes based on the result of those rules.**

Install
-------

[](#install)

Via Composer

```
$ composer require indigophp/ruler
```

Usage
-----

[](#usage)

The package consists of `Rule`s, `Assertion`s, `Results`s, `Modifier`s, `RuleSet`s and a `Processor`.

The main process centers around the `Processor`. This is responsible for taking a `Context` and a `Target` to work out which sets of rules are valid and applying their results. The `Processor` takes a `Context` and applies `Rule`s to it. If the `Rule`s pass then a `Modifier` is applied to the `Target` to modify one or more of the `Target`'s properties.

The `Context` is the data that is being inspected whilst the `Target` is the data that is being modified and is passed by reference. Both can be an array or object or whatever you want and both can be the same thing.

The `Processor` expects to be passed one or more `RuleSet`s. A `RuleSet` is a combination of a single `Rule` and one or more `Modifiers`.

A `Rule` is combined with an `Assertion` to perform logical assertions on the `Context`. `Rule`s should be able to select data from the `Context` and then should apply an `Assertion` to this data to return a boolean value to indicate success or failure.

A `Result` should modify data within the `Target`. They work in much the same way as `Rule`s in that they select data and pass this to a `Modifier` and apply the result.

[`RuleSet` Diagram](resources/ruleset.svg)

[Processor Flow](resources/processor_flow.svg)

[Sample code](resources/example.php)

### Why is this all so complicated

[](#why-is-this-all-so-complicated)

While this whole process might seem complicated it allows for great flexibility when it comes to creating user-buildable rules. The `Rule`s and `Result`s allow a user to pinpoint a single piece of data and define how to examine and modify it.

### Builder

[](#builder)

The `Builder` class can be used to create sets of rules quickly from an array structure. This first requires setting up the various libraries so the `Builder` can create the needed classes for you.

The format of the array is represented [here](resources/builder.json).

### Manager

[](#manager)

The `Manager` class can be used to keep track of multiple sets of the libraries that `Builder` requires. Used in conjunction with a DIC solution this can provide you with an easy way to manage multiple rule "environments".

For example, if you used the logic processor to process rules for product promotions and taxes you most likely want to use different rules and results for both. Using the `Manager` class you can set up an environment for each to be able to quickly create rule sets for both.

Adding a new environment is done via the `Manager::addEnvironment()` method, this takes a name and four "things" for each needed library for `Rule`, `Assertion`, `Result` and `Modifier`. The "thing" can be an array, string or callable.

If an array or `ArrayAccess` is passed then a new library object is created and populated with the values in the array using `AbstractLibrary::add()` with the array keys as the name.

If the thing passed is callable then it is expected to return an instance of `LibraryInterface`.

Finally if the above conditions are not met then the value is treated as a string class name and the `Manager` will attempt to construct it as a new object, passing nothing to the constructor.

Testing
-------

[](#testing)

```
$ phpspec run
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Steve West](https://github.com/stevewest)
- [Márk Sági-Kazár](https://github.com/sagikazarmark)
- [All Contributors](https://github.com/indigophp/ruler/contributors)

Based on the work of [Steve West](https://github.com/stevewest) (original name: [LogicProcessor](https://github.com/ve-interactive/logicprocessor)).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Originally licensed by [Ve Interactive](http://www.veinteractive.com/) under the MIT License.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

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

Total

2

Last Release

4287d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e4e105cea62b616d4cb376b08a849b6a428f646998537de150d16a8eb537b90?d=identicon)[mark.sagikazar](/maintainers/mark.sagikazar)

![](https://www.gravatar.com/avatar/1585b5a08e138e348f5b646231d0f16cb2eae06501fb9462bbc97a794d4de84a?d=identicon)[TamasBarta](/maintainers/TamasBarta)

---

Top Contributors

[![sagikazarmark](https://avatars.githubusercontent.com/u/1226384?v=4)](https://github.com/sagikazarmark "sagikazarmark (42 commits)")

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/indigophp-ruler/health.svg)

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

###  Alternatives

[koalafacade/diamond-console

Laravel Package for generate DDD structure easily for your projects

641.5k](/packages/koalafacade-diamond-console)

PHPackages © 2026

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