bentools/treerex
Composer 安装命令:
composer require bentools/treerex
包简介
🦖 Declarative YAML flowcharts for complex decision trees.
README 文档
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 📚
License 📄
MIT.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-03