PHPackages                             hejunjie/simple-rule-engine - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. hejunjie/simple-rule-engine

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

hejunjie/simple-rule-engine
===========================

一个轻量、易用的 PHP 规则引擎，支持多条件组合与动态规则执行，适用于业务规则判断、数据校验等场景 | A lightweight and flexible PHP rule engine supporting complex conditions and dynamic rule execution—ideal for business logic evaluation and data validation.

v1.0.2(11mo ago)4447↓37.5%1MITPHPPHP &gt;=8.1

Since Apr 29Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/zxc7563598/php-simple-rule-engine)[ Packagist](https://packagist.org/packages/hejunjie/simple-rule-engine)[ RSS](/packages/hejunjie-simple-rule-engine/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (1)

hejunjie/simple-rule-engine
===========================

[](#hejunjiesimple-rule-engine)

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

A lightweight and flexible PHP rule engine supporting complex conditions and dynamic rule execution—ideal for business logic evaluation and data validation.

**This project has been parsed by Zread. If you need a quick overview of the project, you can click here to view it：[Understand this project](https://zread.ai/zxc7563598/php-simple-rule-engine)**

---

🧠 Purpose &amp; Intent
----------------------

[](#-purpose--intent)

When writing PHP on a daily basis, we often encounter "conditional" business logic, such as:

- Does a certain user meet a specific condition?
- Does the current order qualify for a promotional event?
- Does a particular piece of data require further processing?

These types of logic are simple at first, just a series of if, and, or statements. But when you start dealing with 5, 10, or even dozens of conditions all tangled together, things can quickly get messy.

At first, it’s manageable, but after a while, adding, changing, or removing conditions starts to feel like defusing a bomb. Forget about handing it off to someone else – even you, two weeks later, will look at it and cringe.

So, I spent some time developing this PHP Composer package with the goal of organizing these conditional checks in a clearer, more flexible way. The idea is to make the logic more structured and easier to reuse.

---

✨ Features
----------

[](#-features)

- **Easy to Use**: Quickly build rules with an intuitive API, supporting AND/OR combination logic.
- **Highly Extensible**: Includes common built-in operators and supports a custom operator registration mechanism to meet diverse business needs.
- **Flexible Data Structures**: Decouples rules from data, supporting multiple data formats such as arrays and objects.
- **Detailed Rule Evaluation**: Allows access to the evaluation results of each rule, making debugging and logging easier.

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require hejunjie/simple-rule-engine
```

---

🛠️ Usage Examples
-----------------

[](#️-usage-examples)

```
use Hejunjie\SimpleRuleEngine\Rule;
use Hejunjie\SimpleRuleEngine\Engine;

// Define Rules
$rules = [
    new Rule('age', '>=', 18, 'Age must be greater than or equal to 18'),
    new Rule('country', '==', 'SG', 'Country must be Singapore'),
];

// Data to be evaluated
$data = [
    'age' => 20,
    'country' => 'SG',
];

// Evaluation Result
$result = Engine::evaluate($rules, $data, 'AND'); // Return true or false

// Get Detailed Evaluation Information
$details = Engine::evaluateWithDetails($rules, $data);
/*
Return Example:
[
    ['description' => 'Age must be greater than or equal to 18', 'passed' => true],
    ['description' => 'Country must be Singapore', 'passed' => true],
]
*/
```

---

🧩 Built-in Operators
--------------------

[](#-built-in-operators)

OperatorDescriptionAdditional Notes​`==`​Equal toNone​`!=`​Not equal toNone​`>`​Greater thanNone​`>=`​Greater than or equal toNone​`register(new CustomizeOperator());

// You can use customize when defining rules
$rules = [
    new Rule('field', 'customize', 'value', 'Custom rule description'),
    ...
    ...
];
```

---

🎯 Use Cases
-----------

[](#-use-cases)

- **Form Data Validation**: Dynamically validate field values based on user input.
- **Business Rule Evaluation**: Apply rules for scenarios like order processing, access control, etc.
- **Data Filtering and Selection**: Filter datasets based on predefined rules.
- **Config-Driven Logic Control**: Define rules via configuration files to enable flexible business logic.

---

🔧 Additional Toolkits (Can be used independently or installed together)
-----------------------------------------------------------------------

[](#-additional-toolkits-can-be-used-independently-or-installed-together)

This project was originally extracted from [hejunjie/tools](https://github.com/zxc7563598/php-tools). To install all features in one go, feel free to use the all-in-one package:

```
composer require hejunjie/tools
```

Alternatively, feel free to install only the modules you need：

[hejunjie/utils](https://github.com/zxc7563598/php-utils) - A lightweight and practical PHP utility library that offers a collection of commonly used helper functions for files, strings, arrays, and HTTP requests—designed to streamline development and support everyday PHP projects.

[hejunjie/cache](https://github.com/zxc7563598/php-cache) - A layered caching system built with the decorator pattern. Supports combining memory, file, local, and remote caches to improve hit rates and simplify cache logic.

[hejunjie/china-division](https://github.com/zxc7563598/php-china-division) - Regularly updated dataset of China's administrative divisions with ID-card address parsing. Distributed via Composer and versioned for use in forms, validation, and address-related features

[hejunjie/error-log](https://github.com/zxc7563598/php-error-log) - An error logging component using the Chain of Responsibility pattern. Supports multiple output channels like local files, remote APIs, and console logs—ideal for flexible and scalable logging strategies.

[hejunjie/mobile-locator](https://github.com/zxc7563598/php-mobile-locator) - A mobile number lookup library based on Chinese carrier rules. Identifies carriers and regions, suitable for registration checks, user profiling, and data archiving.

[hejunjie/address-parser](https://github.com/zxc7563598/php-address-parser) - An intelligent address parser that extracts name, phone number, ID number, region, and detailed address from unstructured text—perfect for e-commerce, logistics, and CRM systems.

[hejunjie/url-signer](https://github.com/zxc7563598/php-url-signer) - A PHP library for generating URLs with encryption and signature protection—useful for secure resource access and tamper-proof links.

[hejunjie/google-authenticator](https://github.com/zxc7563598/php-google-authenticator) - A PHP library for generating and verifying Time-Based One-Time Passwords (TOTP). Compatible with Google Authenticator and similar apps, with features like secret generation, QR code creation, and OTP verification.

[hejunjie/simple-rule-engine](https://github.com/zxc7563598/php-simple-rule-engine) - A lightweight and flexible PHP rule engine supporting complex conditions and dynamic rule execution—ideal for business logic evaluation and data validation.

👀 All packages follow the principles of being lightweight and practical — designed to save you time and effort. They can be used individually or combined flexibly. Feel free to ⭐ star the project or open an issue anytime!

---

This library will continue to be updated with more practical features. Suggestions and feedback are always welcome — I’ll prioritize new functionality based on community input to help improve development efficiency together.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance59

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

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

Total

3

Last Release

357d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b65d4b40ae456172fb38f63f84bf737ac88031484b1f228b1cc8d71baa80adf?d=identicon)[苏青安](/maintainers/%E8%8B%8F%E9%9D%92%E5%AE%89)

---

Top Contributors

[![zxc7563598](https://avatars.githubusercontent.com/u/46590942?v=4)](https://github.com/zxc7563598 "zxc7563598 (9 commits)")

---

Tags

business-rulescomposer-packagedynamic-ruleslightweightopen-sourcephpphp8rule-enginesimple-rule-enginevalidation

### Embed Badge

![Health badge](/badges/hejunjie-simple-rule-engine/health.svg)

```
[![Health](https://phpackages.com/badges/hejunjie-simple-rule-engine/health.svg)](https://phpackages.com/packages/hejunjie-simple-rule-engine)
```

###  Alternatives

[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[aporat/store-receipt-validator

PHP receipt validator for Apple App Store and Amazon Appstore

6503.9M9](/packages/aporat-store-receipt-validator)[elegantweb/sanitizer

Sanitization library for PHP and the Laravel framework.

115950.4k2](/packages/elegantweb-sanitizer)[arondeparon/laravel-request-sanitizer

An easy to use request sanitizer that allows you to sanitize your form data before validating it.

112151.6k1](/packages/arondeparon-laravel-request-sanitizer)[timacdonald/rule-builder

A fluent rule builder for Laravel validation rule generation.

1027.7k](/packages/timacdonald-rule-builder)

PHPackages © 2026

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