mojolyon / axiom
商业规则管理系统
v0.1.0
2014-11-20 13:01 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- atoum/atoum: dev-master
This package is not auto-updated.
Last update: 2024-09-24 05:20:55 UTC
README
一个简单的PHP商业规则管理系统
维基百科定义
BRMS(商业规则管理系统)是一种软件系统,用于定义、部署、执行、监控和维护组织或企业中运营系统使用的各种决策逻辑的多样性和复杂性。这种逻辑也被称为业务规则,包括政策、要求和条件语句,用于确定在应用程序和系统中发生的战术行动。
受Jim Arlow和Ila Neustadt所著的《企业模式与MDA》一书启发
安装
在您的composer.json中添加以下内容
{
"require": {
"mojolyon/axiom": "~0.1"
}
}
用法
// Setting rule with default values $rule = new Rule('eligibleForDiscount'); $rule->add(new RuleElement\DateVariable('minCustomerSince', new \DateTime('2014-01-01 00:00:00'))) ->add(new RuleElement\DateVariable('customerSince', new \DateTime('2014-01-01 00:00:00'))) ->operator(Operator::GREATHER_THAN) ->variable('minOrder', 5) ->variable('customerNumberOrder', 0) ->operator(Operator::LESSERTHAN_OR_EQUAL) ->operator('and'); $ruleContext = new Context('eligibleForDiscountCustomer'); $ruleContext->add(new RuleElement\DateVariable('customerSince', new \DateTime('2013-12-11 22:00:00'))) ->variable('customerNumberOrder', 13); $isEligible = $rule->evaluate($ruleContext); if ($isEligible->getValue()) { echo "Customer eligible for discount"; } else { echo "Customer not eligible for discount"; } // will output "Customer eligible for discount" // the rule is evaluate as : ((minCustomerSince > customerSince) and (minOrder <= customerNumberOrder))
有三种类型的规则元素
- 命题:值必须是布尔值
- 变量:值可以是任何东西
- 日期变量:值必须是DateTime实例
基础规则有添加元素的辅助函数
- Rule::operator()
- Rule::proposition()
- Rule::variable()
测试
$ php composer.phar install --dev
$ ./vendor/bin/atoum