You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A lightweight and flexible PHP rule engine supporting complex conditions and dynamic rule execution—ideal for business logic evaluation and data validation.
4
9
5
10
---
6
11
7
-
## 🧠 用途 & 初衷
12
+
## 🧠 Purpose & Intent
8
13
9
-
日常写 PHP 的时候,我们经常会遇到一类“判断性”的业务逻辑,比如:
14
+
When writing PHP on a daily basis, we often encounter "conditional" business logic, such as:
10
15
11
-
-某个用户是否符合某个条件?
12
-
-当前订单是否满足参加活动的资格?
13
-
-某条数据是否需要做进一步处理?
16
+
-Does a certain user meet a specific condition?
17
+
-Does the current order qualify for a promotional event?
18
+
-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.
20
25
21
26
---
22
27
23
-
## ✨ 特点
28
+
## ✨ Features
24
29
25
-
-**简单易用**:通过直观的 API 快速构建规则,支持 AND / OR 组合逻辑。
26
-
-**高度可扩展**:内置常用操作符,支持自定义操作符注册机制,满足多样化业务需求。
27
-
-**灵活的数据结构**:规则与数据解耦,支持数组、对象等多种数据形式。
28
-
-**详细的规则评估**:可获取每条规则的评估结果,便于调试与日志记录。
30
+
-**Easy to Use**: Quickly build rules with an intuitive API, supporting AND/OR combination logic.
31
+
-**Highly Extensible**: Includes common built-in operators and supports a custom operator registration mechanism to meet diverse business needs.
32
+
-**Flexible Data Structures**: Decouples rules from data, supporting multiple data formats such as arrays and objects.
33
+
-**Detailed Rule Evaluation**: Allows access to the evaluation results of each rule, making debugging and logging easier.
29
34
30
35
---
31
36
32
-
## 📦 安装
37
+
## 📦 Installation
33
38
34
-
使用 Composer 安装:
39
+
Install via Composer:
35
40
36
41
```bash
37
42
composer require hejunjie/simple-rule-engine
38
43
```
39
44
40
45
---
41
46
42
-
## 🛠️ 用法示例
47
+
## 🛠️ Usage Examples
43
48
44
49
```php
45
50
use Hejunjie\SimpleRuleEngine\Rule;
46
51
use Hejunjie\SimpleRuleEngine\Engine;
47
52
48
-
// 定义规则
53
+
// Define Rules
49
54
$rules = [
50
-
new Rule('age', '>=', 18, '年龄必须大于等于18岁'),
51
-
new Rule('country', '==', 'SG', '国家必须是新加坡'),
55
+
new Rule('age', '>=', 18, 'Age must be greater than or equal to 18'),
56
+
new Rule('country', '==', 'SG', 'Country must be Singapore'),
This project was originally extracted from [hejunjie/tools](https://github.com/zxc7563598/php-tools).
168
+
To install all features in one go, feel free to use the all-in-one package:
163
169
164
170
```bash
165
171
composer require hejunjie/tools
166
172
```
167
173
168
-
当然你也可以按需选择安装以下功能模块:
174
+
Alternatively, feel free to install only the modules you need:
175
+
176
+
[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.
183
191
184
-
[hejunjie/google-authenticator](https://github.com/zxc7563598/php-google-authenticator) - Google Authenticator 及类似应用的密钥生成、二维码创建和 OTP 验证。
192
+
[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.
185
193
186
-
👀 所有包都遵循「轻量实用、解放双手」的原则,能单独用,也能组合用,自由度高,欢迎 star 🌟 或提 issue。
194
+
👀 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.
0 commit comments