vestin/logic-checker 问题修复 & 功能扩展

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

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

vestin/logic-checker

Composer 安装命令:

composer require vestin/logic-checker

包简介

复杂逻辑检查器

README 文档

README

a reusable,SRP component for complex logic checker.

  • write DRY code
  • preventing to use lots of if else statement
  • make logic checker reusable

Build Status

usage:

install

composer require "vestin/logic-checker:*",

example:

write a checker

use Vestin\Checker\CheckNotPassException;

class MathAddChecker implements CheckerInterface
{

    private $paramOne;
    private $paramTwo;
    private $result;

    public function __construct($paramOne, $paramTwo, $result)
    {
        $this->paramOne = $paramOne;
        $this->paramTwo = $paramTwo;
        $this->result = $result;
    }


    public function check() {
        if( ($this->paramOne + $this->paramTwo) != $this->result){
            throw new CheckNotPassException('calc error');
        }
    }

}

check passed example:

include 'vendor/autolad.php'

$dispatcher = new \Vestin\Checker\Dispatchers\SimpleDispatcher();
$checkerBus = new \Vestin\Checker\CheckerBus($dispatcher);

$checker = new MathAddChecker(1, 2, 3); // 1+2=3
$checker2 = new MathAddChecker(2, 3, 5); // 2+3=5

$checkerBus->addChecker($checker)
           ->addChecker($cherker2);
    
if($checkerBus->check()){
    // check pass
    echo 'check passed'; // this will called
}else{
    // check not pass
    $error = $checkerBus->getError();
}

check not passed example:

include 'vendor/autolad.php'

$dispatcher = new \Vestin\Checker\Dispatchers\SimpleDispatcher();
$checkerBus = new \Vestin\Checker\CheckerBus($dispatcher);

$checker = new MathAddChecker(1, 2, 3); // 1+2=3
$checker2 = new MathAddChecker(2, 3, 6); // 2+3=5 this is wrong

$checkerBus->addChecker($checker)
           ->addChecker($cherker2);
    
if($checkerBus->check()){
    // check pass
    // echo 'check passed';
}else{
    // check not pass
    // this will called
    $error = $checkerBus->getError(); // $error will be a string 'calc error';
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固