Download the PHP package hejunjie/simple-rule-engine without Composer
On this page you can find all versions of the php package hejunjie/simple-rule-engine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hejunjie/simple-rule-engine
More information about hejunjie/simple-rule-engine
Files in hejunjie/simple-rule-engine
Package simple-rule-engine
Short Description 一个轻量、易用的 PHP 规则引擎,支持多条件组合与动态规则执行,适用于业务规则判断、数据校验等场景 | A lightweight and flexible PHP rule engine supporting complex conditions and dynamic rule execution—ideal for business logic evaluation and data validation.
License MIT
Informations about the package simple-rule-engine
hejunjie/simple-rule-engine
简体中文 | English
A lightweight, easy-to-use PHP rule engine supporting multi-condition combinations and dynamic rule execution — ideal for business logic evaluation and data validation.
This project has been parsed by Zread. Click to explore the project structure and code navigation.
✨ Features
- Clean API: Build and execute rules in just a few lines with
Rule+Engine, supporting AND / OR combination logic. - Rich Built-in Operators: 17 operators out of the box covering comparison, string, array, and date scenarios.
- Highly Extensible: Register custom operators by implementing the
OperatorInterfaceto handle specialized business needs. - Decoupled Rules and Data: Rule definitions are fully separated from data evaluation, supporting arrays, objects, and more.
- Detailed Evaluation Feedback:
evaluateWithDetailsreturns the pass/fail status of each rule, making debugging and logging straightforward.
📋 Requirements
- PHP >= 8.1
- nesbot/carbon ^3.9 (required by date operators)
📦 Installation
🚀 Quick Start
📖 Usage
Basic Evaluation
Engine::evaluate() accepts a list of rules, data, and a combination strategy, returning a boolean.
Getting Detailed Results
Engine::evaluateWithDetails() returns the evaluation result for each rule:
Using RuleGroup
If you need more flexible composition (e.g., reusing the same group of rules across different scenarios), you can use RuleGroup directly:
Custom Operators
Implement the OperatorInterface and register through OperatorFactory:
🧩 Built-in Operators
Comparison Operators
| Operator | Description | Example Value |
|---|---|---|
== |
Equal to | 18 |
!= |
Not equal to | 18 |
> |
Greater than | 18 |
>= |
Greater than or equal to | 18 |
< |
Less than | 18 |
<= |
Less than or equal to | 18 |
Set Operators
| Operator | Description | Example Value |
|---|---|---|
in |
Value in array | ['SG', 'MY', 'TH'] |
not_in |
Value not in array | ['SG', 'MY', 'TH'] |
String Operators
| Operator | Description | Example Value |
|---|---|---|
contains |
Contains substring | 'admin' |
not_contains |
Does not contain substring | 'admin' |
start_swith |
Starts with | 'VIP_' |
end_swith |
Ends with | '@example.com' |
Range Operators
| Operator | Description | Example Value |
|---|---|---|
between |
Value within range | [18, 65] |
not_between |
Value outside range | [18, 65] |
Date Operators
| Operator | Description | Example Value |
|---|---|---|
before_date |
Date is before | '2025-01-01' |
after_date |
Date is after | '2025-01-01' |
date_equal |
Date is equal to | '2025-01-01' |
Date operators are powered by Carbon and support all common date formats as well as timestamps.
🎯 Use Cases
- Form Data Validation: Dynamically validate user-submitted fields against conditions.
- Business Rule Evaluation: Order status transitions, campaign eligibility, access control, and more.
- Data Filtering: Filter datasets based on predefined rules.
- Config-Driven Logic: Define rules via configuration files or databases for flexible business logic.
📁 Directory Structure
🧪 Running Tests
🙌 Contributing
If this project helps you, a Star ⭐ would be much appreciated!
For questions or suggestions, feel free to open an Issue. Let's make it better together.