bentools / treerex
🦖 Declarative YAML flowcharts for complex decision trees.
1.0-alpha1
2026-03-10 15:08 UTC
Requires
- php: >=8.4
- psr/container: ^2.0
- symfony/expression-language: ^7.3|^8.0
- symfony/options-resolver: ^7.3|^8.0
- symfony/yaml: ^7.3|^8.0
Requires (Dev)
- bentools/cartesian-product: ^2.0
- friendsofphp/php-cs-fixer: ^3.90
- pestphp/pest: ^4.1
- phpstan/phpstan: ^2.1
- symfony/var-dumper: ^7.3|^8.0
This package is auto-updated.
Last update: 2026-03-10 15:09:38 UTC
README
Declaratively describe complex decision trees ("flowcharts") in YAML and run them against arbitrary subjects.
TL;DR (what you get in practice) 🫵
- ✅ Zero if‑else spaghetti – complex validation / eligibility logic lives in YAML, not buried in controllers.
- 🧩 Composable rules – re‑use the same checker services across many flowcharts.
- 🔍 Full observability – inspect the last node, the full decision history, and enriched context.
- 🧪 Test‑friendly – feed any subject + context, assert the final result and the reasons attached in context.
- 🧠 Business‑driven – Product Owners can reason about the YAML flowchart without reading PHP.
- ⚡ Side effects – trigger external actions (dispatch messages, write to cache, …) alongside decisions.
What it looks like
# config/user_can_edit_post.yaml options: defaultChecker: BenTools\TreeRex\Checker\ExpressionLanguageChecker context: requiresApproval: ~ entrypoint: criteria: "subject.isAdmin()" when@true: end: true when@false: criteria: "subject.id === context.post.authorId" when@true: end: true when@false: criteria: "subject.roles in ['ROLE_REVIEWER']" when@true: end: result: true context: requiresApproval: true
use BenTools\TreeRex\Factory\FlowchartYamlFactory; use BenTools\TreeRex\Runner\FlowchartRunner; use BenTools\TreeRex\Runner\RunnerContext; $flowchart = new FlowchartYamlFactory()->parseYamlFile(__DIR__.'/config/user_can_edit_post.yaml'); $runner = new FlowchartRunner(); $context = new RunnerContext(['post' => $post]); // <-- will be merged with `requiresApproval` above $canEdit = $runner->satisfies($user, $flowchart, $context); var_dump($canEdit); // bool var_dump($context['requiresApproval']); // bool|null var_dump($context->state); // RunnerState -> gives you the full history of decisions
Installation 💾
composer require bentools/treerex
Table of contents 📚
License 📄
MIT.