PHPackages                             yl0711-coder/ruleflow-php - 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. yl0711-coder/ruleflow-php

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

yl0711-coder/ruleflow-php
=========================

A lightweight Decision List rule engine for PHP and Laravel.

v0.3.5(1mo ago)5449[1 issues](https://github.com/yl0711-coder/ruleflow-php/issues)MITPHPPHP ^8.1CI passing

Since Apr 20Pushed 1mo agoCompare

[ Source](https://github.com/yl0711-coder/ruleflow-php)[ Packagist](https://packagist.org/packages/yl0711-coder/ruleflow-php)[ Docs](https://github.com/yl0711-coder/ruleflow-php)[ RSS](/packages/yl0711-coder-ruleflow-php/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (7)Dependencies (8)Versions (14)Used By (0)

RuleFlow PHP
============

[](#ruleflow-php)

[English](README.md) | [简体中文](README.zh-CN.md)

[![Tests](https://github.com/yl0711-coder/ruleflow-php/actions/workflows/tests.yml/badge.svg)](https://github.com/yl0711-coder/ruleflow-php/actions/workflows/tests.yml)[![Packagist Version](https://camo.githubusercontent.com/67f9cdd0d633f7cca8279c6fe339c0a44a3a2c805d1d24125c9f66683d5cd49e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796c303731312d636f6465722f72756c65666c6f772d7068702e737667)](https://packagist.org/packages/yl0711-coder/ruleflow-php)[![License](https://camo.githubusercontent.com/0572363cc0b4ee73cc533abbd76e9ed91b0b23acf5a7800fc407829442f68adb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f796c303731312d636f6465722f72756c65666c6f772d7068702e737667)](LICENSE)

A lightweight Decision List rule engine for PHP and Laravel.

RuleFlow helps backend teams move complex business rules out of hard-coded `if/else` logic and into testable, configurable, and traceable rule definitions.

It is designed for risk control, content moderation, marketing eligibility, access control, and business decision workflows.

Why This Project Exists
-----------------------

[](#why-this-project-exists)

Many PHP systems start with a few inline checks:

```
if ($order->amount > 1000 && $user->risk_score < 60) {
    return 'reject';
}
```

That works until the rules become:

- scattered across controllers, services, jobs, and listeners
- hard to validate before deployment
- hard to explain to support, operations, or reviewers
- risky to change because business logic is mixed with application flow

RuleFlow keeps the model intentionally small:

- it uses a Decision List model: deterministic priority order, first matching decision by default
- rules are structured data, not framework-specific code
- evaluation is deterministic and priority-based
- decisions can be inspected with `trace()` or summarized with `explain()`
- Laravel integration exists, but the core stays framework-agnostic

RuleFlow is not a RETE inference engine. It is for PHP business decisions where the problem is scattered rules, unsafe changes, and unclear explanations rather than working-memory inference or complex event processing.

What You Get
------------

[](#what-you-get)

- First-match and all-match evaluation with `evaluate()` and `evaluateAll()`
- Nested condition groups such as `A AND (B OR C)`
- Built-in operators for equality, numeric checks, arrays, existence, strings, and regex
- Rule validation before runtime
- Trace diagnostics with failure reasons and timing
- Compact `explain()` output for APIs, logs, and support tools
- Sensitive-value redaction with `sensitive: true`
- Optional rule metadata for ownership, versions, tickets, and rollout notes
- Laravel config loading, cache support, and `php artisan ruleflow:validate`

Good Fit
--------

[](#good-fit)

RuleFlow is a good fit when you need:

- order or payment risk decisions
- content moderation routing
- campaign or coupon eligibility checks
- access-control decisions with request context
- business rules that need to be reviewed, tested, and explained

It is not trying to be:

- a visual rule builder
- a BPMN or workflow platform
- a distributed decision service
- a replacement for full policy, validation, or workflow systems

Why Not A Heavy Rule Engine
---------------------------

[](#why-not-a-heavy-rule-engine)

Many teams do not need a full decision platform. They need a small library that can live inside an existing PHP service and solve one practical problem: replace scattered conditional business logic with something structured, testable, and explainable.

RuleFlow is intentionally optimized for that use case:

- no external server to run
- no DSL or visual designer to learn
- no database schema required
- no framework lock-in for core usage
- no large integration surface before the first useful rule ships

Compared with heavier rule engines, RuleFlow trades breadth for clarity:

- fewer concepts to learn
- faster adoption inside an existing Laravel or PHP codebase
- easier code review because rules stay close to application context
- easier production debugging because `trace()` and `explain()` are built in

If your problem is "we need a rules platform", RuleFlow is probably too small. If your problem is "our PHP business logic is turning into untestable if/else sprawl", RuleFlow is the right size.

Project Status
--------------

[](#project-status)

Current release line: `v0.3.x`

The project already includes:

- Packagist distribution
- CI with PHPUnit, PHPCS, PHPStan, examples, and install validation
- changelog and GitHub Release flow
- production, security, and Laravel documentation

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

[](#installation)

### Via Packagist

[](#via-packagist)

```
composer require yl0711-coder/ruleflow-php
```

### From GitHub VCS

[](#from-github-vcs)

```
composer config repositories.ruleflow vcs https://github.com/yl0711-coder/ruleflow-php
composer require yl0711-coder/ruleflow-php:^0.3
```

The package requires PHP 8.1 or later.

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

[](#quick-start)

```
use RuleFlow\Engine;
use RuleFlow\RuleSet;

$rules = [
    [
        'name' => 'high_risk_order',
        'priority' => 100,
        'match' => 'all',
        'conditions' => [
            ['field' => 'order.amount', 'operator' => '>', 'value' => 1000],
            ['field' => 'user.risk_score', 'operator' => '',
                    'expected' => 1000,
                    'passed' => true,
                    'duration_ms' => 0.011,
                ],
                [
                    'field' => 'user.risk_score',
                    'exists' => true,
                    'missing' => false,
                    'sensitive' => false,
                    'actual' => 45,
                    'operator' => '=', 'value' => 3],
    ],
    'action' => 'manual_review',
]
```

Nested Condition Groups
-----------------------

[](#nested-condition-groups)

RuleFlow also supports nested condition groups for cases like `A AND (B OR C)`:

```
[
    'name' => 'high_risk_order',
    'match' => 'all',
    'conditions' => [
        ['field' => 'order.amount', 'operator' => '>', 'value' => 1000],
        [
            'match' => 'any',
            'conditions' => [
                ['field' => 'user.risk_score', 'operator' => '
