PHPackages                             fr3on/php-ruleset - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. fr3on/php-ruleset

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

fr3on/php-ruleset
=================

Standalone business rule and expression evaluator for PHP 8.4+

0.0.1(1mo ago)0220↓100%MITPHPPHP &gt;=8.4CI passing

Since Apr 13Pushed 1mo agoCompare

[ Source](https://github.com/fr3on/php-ruleset)[ Packagist](https://packagist.org/packages/fr3on/php-ruleset)[ RSS](/packages/fr3on-php-ruleset/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

php-ruleset
===========

[](#php-ruleset)

[![CI](https://github.com/fr3on/php-ruleset/actions/workflows/ci.yml/badge.svg)](https://github.com/fr3on/php-ruleset/actions/workflows/ci.yml)[![License](https://camo.githubusercontent.com/64bed849576f94880afaf008c7f2ee0b7219099813efa7c36966070105a8b6b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6672336f6e2f7068702d72756c65736574)](https://github.com/fr3on/php-ruleset/blob/main/LICENSE)

A standalone, framework-agnostic PHP 8.4+ expression and business rule evaluator. Secure, fast, and 100% type-safe (PHPStan Level 9).

Features
--------

[](#features)

- **Recursive Descent Parser**: Pure AST-based evaluation (no `eval()`).
- **Secure by Design**: Strict whitelist for all identifiers and functions.
- **Dot-Notation**: Easily resolve nested data like `user.profile.age`.
- **Zero Dependencies**: 100% standalone.
- **PHP 8.4+**: Leverages property hooks and readonly classes.

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

[](#installation)

```
composer require fr3on/php-ruleset
```

Quick Start
-----------

[](#quick-start)

```
use Fr3on\Ruleset\Ruleset;

$ruleset = new Ruleset();

$rule = 'order.total * 1.15 > 1000 AND user.country IN ["SA", "AE"]';
$data = [
    'order' => ['total' => 1000],
    'user' => ['country' => 'SA']
];

$result = $ruleset->execute($rule, $data); // true
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Functions

[](#custom-functions)

```
$ruleset->registerFunction('is_premium', fn($userId) => $db->isPremium($userId));

$ruleset->execute('is_premium(user.id) AND order.discount > 0.2', $data);
```

### Pre-parsing &amp; Caching

[](#pre-parsing--caching)

For high-performance scenarios, parse the expression once and cache the AST.

```
$ast = $ruleset->parse('x > 10');

// Reuse $ast across many evaluations
$result = $ruleset->evaluate($ast, ['x' => 15]);
```

Security
--------

[](#security)

RuleSet uses a strict whitelist approach.

1. All identifiers must exist in the provided context.
2. Only whitelisted functions can be called.
3. Math operations enforce numeric types strictly.

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance89

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community3

Small or concentrated contributor base

Maturity41

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

Unknown

Total

1

Last Release

57d ago

### Community

---

Top Contributors

[![fr3on](https://avatars.githubusercontent.com/u/26393383?v=4)](https://github.com/fr3on "fr3on (5 commits)")

---

Tags

business-rulesexpression-evaluatorlexerparserphprules

### Embed Badge

![Health badge](/badges/fr3on-php-ruleset/health.svg)

```
[![Health](https://phpackages.com/badges/fr3on-php-ruleset/health.svg)](https://phpackages.com/packages/fr3on-php-ruleset)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[karriere/json-decoder

JsonDecoder implementation that allows you to convert your JSON data into PHP class objects

141439.4k12](/packages/karriere-json-decoder)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

45143.1k6](/packages/jstewmc-rtf)[json-mapper/laravel-package

The JsonMapper package for Laravel

25188.9k3](/packages/json-mapper-laravel-package)[jamesmoss/toml

A parser for TOML implemented in PHP.

3231.7k15](/packages/jamesmoss-toml)

PHPackages © 2026

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