sinevia/php-library-business-rule
Composer 安装命令:
composer require sinevia/php-library-business-rule
包简介
PHP Library Business Rule
README 文档
README
A business rule defines or constrains some aspect of business. Given a specified context (data) a business rule always resolves to either true or false.
Formal specification: // Given {context} When {condition(s)} Then {pass} Or {fail}
Usage
- Direct usage
$rule = (new BusinessRule())->context([])->condition(function($context){ return true; }); if ($rule->fails()) { // Execute fail logic } if ($rule->passes()) { // Execute pass logic }
- Extend into a separate class. Allows to be re-used (avoid duplication of business logic)
// 1. Specify the business rule class class AllowAccessRule extends BusinessRule { function __construct() { $this->condition(function($context){ return ($context['user']->isEmailConfirmed() AND $context['user']->isActive()); }); } } // Use the shortcut init function with the context to initialize the rule if (AllowAccessRule::init(['user'=>$user)->fails()) { die('You are not allowed access to this part of the website'); }
统计信息
- 总下载量: 66
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2020-02-20