Download the PHP package philiprehberger/php-rule-engine without Composer
On this page you can find all versions of the php package philiprehberger/php-rule-engine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download philiprehberger/php-rule-engine
More information about philiprehberger/php-rule-engine
Files in philiprehberger/php-rule-engine
Download philiprehberger/php-rule-engine
More information about philiprehberger/php-rule-engine
Files in philiprehberger/php-rule-engine
Vendor philiprehberger
Package php-rule-engine
Short Description Lightweight business rule engine with declarative conditions and actions
License MIT
Homepage https://github.com/philiprehberger/php-rule-engine
Package php-rule-engine
Short Description Lightweight business rule engine with declarative conditions and actions
License MIT
Homepage https://github.com/philiprehberger/php-rule-engine
Please rate this library. Is it a good library?
Informations about the package php-rule-engine
PHP Rule Engine
Lightweight business rule engine with declarative conditions and actions.
Requirements
- PHP 8.2+
Installation
Usage
Basic Rule
Multiple Conditions
Negated Conditions
Priority and Stop-on-Match
First Match Only
Nested Context with Dot Notation
Compiled Rule Engine
Audit Mode
Rule Validation
Custom Context Accessor
Implement ContextAccessor to read values from any data structure:
API
RuleEngine
| Method | Description |
|---|---|
RuleEngine::create(?ContextAccessor $accessor = null): self |
Create a new engine instance |
->rule(string $name): RuleBuilder |
Begin defining a named rule |
->evaluate(mixed $context): EvaluationResult |
Evaluate all rules, return all matches |
->evaluateFirst(mixed $context): ?RuleResult |
Evaluate rules, return first match only |
->compile(): CompiledRuleEngine |
Pre-compile rules into optimized closures |
->withAudit(): self |
Enable audit mode for detailed tracking |
->validate(): array |
Validate rule configuration, return warnings |
RuleBuilder
| Method | Description |
|---|---|
->when(string $path, string $operator, mixed $value) |
Add the first condition |
->andWhen(string $path, string $operator, mixed $value) |
Add an AND condition |
->orWhen(string $path, string $operator, mixed $value) |
Add an OR condition |
->notWhen(string $path, string $operator, mixed $value) |
Add a negated AND condition |
->then(callable $action) |
Set the action to execute on match |
->priority(int $priority) |
Set rule priority (higher runs first) |
->stopOnMatch(bool $stop = true) |
Stop evaluation after this rule matches |
->build(): RuleEngine |
Build the rule and return the engine |
CompiledRuleEngine
| Method | Description |
|---|---|
->evaluate(mixed $context): EvaluationResult |
Evaluate compiled rules, return all matches |
->evaluateFirst(mixed $context): ?RuleResult |
Evaluate compiled rules, return first match only |
Operators
| Operator | Description |
|---|---|
=, == |
Loose equality |
=== |
Strict equality |
!=, <> |
Loose inequality |
!== |
Strict inequality |
>, <, >=, <= |
Comparison |
in |
Value exists in array |
not_in |
Value does not exist in array |
contains |
String contains substring |
starts_with |
String starts with prefix |
ends_with |
String ends with suffix |
matches |
Regex match |
between |
Value is between two values (inclusive) |
EvaluationResult
| Method | Description |
|---|---|
->hasMatches(): bool |
Whether any rules matched |
->count(): int |
Number of matched rules |
->first(): ?RuleResult |
First matched result or null |
->actionResults(): array |
All action return values |
->ruleNames(): array |
All matched rule names |
AuditResult (extends EvaluationResult)
| Method | Description |
|---|---|
->auditEntries(): array |
All audit entries |
->evaluatedCount(): int |
Number of rules evaluated |
->skippedCount(): int |
Number of rules skipped |
RuleResult
| Property | Type | Description |
|---|---|---|
$ruleName |
string |
Name of the matched rule |
$actionResult |
mixed |
Return value of the action |
Development
Support
If you find this project useful:
License
MIT
All versions of php-rule-engine with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.2
The package philiprehberger/php-rule-engine contains the following files
Loading the files please wait ...