定制 bentools/treerex 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bentools/treerex

Composer 安装命令:

composer require bentools/treerex

包简介

🦖 Declarative YAML flowcharts for complex decision trees.

README 文档

README

CI Workflow codecov

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-03