pengboomouch/regulus-php 问题修复 & 功能扩展

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

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

pengboomouch/regulus-php

Composer 安装命令:

composer require pengboomouch/regulus-php

包简介

Small rule library.

README 文档

README

Regulus Php Version - Lightweight rule organization.

Install

composer require pengboomouch/regulus-php

Example

// Define some rules and conditions
$disableRow = new \DisableRowRule(
    new SomeRowCondition(),
    new SomeSecurityCondition()
);

// Init a group and add all rules to it
$regulus = new \Regulus\Regulus();
$regulus->createGroup('row_rules');
$regulus->addRuleTo('row_rules', $disableRow);

Resolve all rules

$finalResult = $regulus->resolveAll();

if ($finalResult->isFulfilled()) {
    // Do something final
    // ...
} else {
    $failedRules = $finalResult->getFailedRules();
    $failedConditions = $failedRules->getFailedConditions();
    
    // Log or do something else
}

Resolve a specific rule

$disableRowResult = $regulus->resolveRuleIn('row_rules', DisableRowRule::class);
if ($disableRowResult->isFulfilled()) {
    // Disable the row
    // ...
}

Resolve specific group

$rowRuleGroupResult = $resolver->resolveGroup('row_rules');
if ($rowRuleGroupResult->isFulfilled()) {
    // Do something to the rows
    // ...
}

Create conditions

Define acceptance conditions to be fulfilled.

class MyCondition implements \Regulus\Interface\Condition
{
    // Inject all repositories or services you need
    public function __construct(private SomeService $someService)
    {}
    
    public function isFulfilled(): bool
    {
        // Determine if the condition is fulfilled
        // ...
        
        return true;
    }
}

Create rules

A rule can have multiple conditions. You can decide for yourself when to return a fail or success result.

class MyRule extends \Regulus\Core\AbstractRule
{
    // Inject all needed conditions for this rule
    public function __construct(private MyCondition $someRowCondition)
    {}

    public function resolve(): RuleResult
    {
        $succeededConditions = [];
        $failedConditions = [];
        
        // Determine if the result is fulfilled
        if(!$this->someRowCondition->isFulfilled()) {
            $isFulfilled = false;
            $failedConditions[] = $this->someRowCondition;
        } else {
            $isFulfilled = true;
            $succeededConditions[] = $this->someRowCondition;
        }

        return $this->createResult(
            $isFulfilled,
            self,
            $succeededConditions,
            $failedConditions
        );
    }
}

Logs

You can track all conditions for debugging.

    $allConditions = $disableRowResult->getAllConditions();
    
    $fulfilledConditions = $disableRowResult->getFulfilledConditions();
    
    $failedConditions = $disableRowResult->getFailedConditions();

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固