bentools / treerex
🦖 Declarative YAML flowcharts for complex decision trees.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/bentools/treerex
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: 2025-12-03 17:15:50 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.
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 📚
- 🚀 Getting started
- 🔍 Flowchart state & context
- đź§ Core concepts
- ⚙️ Advanced usage
- 🤝 Contributing
License đź“„
MIT.