fly321/rule-engine 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

fly321/rule-engine

最新稳定版本:v0.0.5

Composer 安装命令:

composer require fly321/rule-engine

包简介

通用规则引擎

README 文档

README

Rule Engine

这是一个简单的PHP规则引擎包。该项目使用PHP和Composer来构建和运行规则引擎。

需要

  • PHP 7.4 or higher
  • Composer

安装

  1. require composer

    composer require fly321/rule-engine
  2. 具体示例demo

    php test/demo.php

use

规则引擎 - 实现RuleInterface接口

<?php

namespace Fly\RuleEngine\Rules;

use Fly\RuleEngine\Interfaces\RuleContextInterface;
use Fly\RuleEngine\Interfaces\RuleInterface;

class DemoRule implements RuleInterface
{
    /**
     * @inheritDoc
     */
    public function matches(RuleContextInterface $context): bool
    {
        return $context->containsKey("num1")
            &&
            $context->containsKey("num2")
            &&
            $context->get("num1") < $context->get("num2");
    }

    /**
     * @inheritDoc
     */
    public function execute(RuleContextInterface $context): void
    {
        var_dump($context->get("num1"), $context->get("num2"));
        echo "num1 < num2\n";
        $context->set("num_bool", true);
    }

    /**
     * @inheritDoc
     */
    public function notMatches(RuleContextInterface $context): void
    {
        var_dump($context->get("num1"), $context->get("num2"));
        echo "num1 >= num2\n";
        $context->set("num_bool", false);
    }
}

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-28