PHPackages                             prohalexey/the-choice - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. prohalexey/the-choice

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

prohalexey/the-choice
=====================

3.0.1(3mo ago)253.5k—4.4%5[2 issues](https://github.com/prohalexey/TheChoice/issues)MITPHPPHP &gt;=8.4

Since Nov 25Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/prohalexey/TheChoice)[ Packagist](https://packagist.org/packages/prohalexey/the-choice)[ RSS](/packages/prohalexey-the-choice/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (30)Versions (10)Used By (0)

TheChoice - Business Rule Engine
================================

[](#thechoice---business-rule-engine)

[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/prohalexey/TheChoice/master/LICENSE)

A powerful and flexible Business Rule Engine for PHP that allows you to separate business logic from your application code.

Features
--------

[](#features)

This library helps you simplify the implementation of complex business rules such as:

- Complex discount calculations
- Customer bonus systems
- User permission resolution
- Dynamic pricing strategies

**Why use TheChoice?** If you find yourself constantly modifying business conditions in your code, this library allows you to move those conditions to external configuration sources. You can even create a web interface to edit configurations dynamically.

### Key Benefits

[](#key-benefits)

- ✅ Rules written in JSON or YAML format
- ✅ Store rules in files or databases
- ✅ Serializable and cacheable configurations (PSR-16)
- ✅ PSR-11 compatible container support
- ✅ Extensible with custom operators and contexts
- ✅ Rule Engine — evaluate multiple rules in a single run
- ✅ Rule Registry — named rules with tags, version, and metadata
- ✅ Rule Validator — static analysis of rules before execution
- ✅ Evaluation Trace — step-by-step debugging of rule evaluation
- ✅ Event System — PSR-14 lifecycle and node-level events for observability
- ✅ Switch Node — multi-branch dispatch on a single context value
- ✅ Fluent PHP Builder (DSL) — build rule trees programmatically without JSON/YAML
- ✅ Node Exporter — serialize rule trees back to JSON or YAML
- ✅ Storage variable references — use `$storageKey` as operator values

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration Formats](#configuration-formats)
    - [JSON](#json-configuration-example)
    - [YAML](#yaml-configuration-example)
- [Core Concepts](#core-concepts)
    - [Node Types](#node-types) — Root, Value, Context, Condition, Collection, **Switch**
    - [Built-in Operators](#built-in-operators)
    - [Modifiers](#modifiers)
    - [Storage Variable References](#storage-variable-references)
- [Rule Engine](#rule-engine) — multi-rule evaluation
- [Rule Registry](#rule-registry) — named rules with metadata
- [Rule Validator](#rule-validator) — static analysis / linter
- [Evaluation Trace](#evaluation-trace) — debugging
- [Event System](#event-system) — PSR-14 lifecycle &amp; node events
- [Caching](#caching) — PSR-16
- [Container Integration](#container-integration) — Built-in &amp; Symfony
- [Advanced Features](#advanced-features) — custom contexts, operators, processor flushing
- [Fluent Builder (DSL)](#fluent-builder-dsl) — build rules in PHP without JSON/YAML
- [Node Exporter](#node-exporter) — serialize rule trees to JSON or YAML
- [License](#license)

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

[](#installation)

```
composer require prohalexey/the-choice
```

**Requirements:** PHP 8.4+

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

[](#quick-start)

```
