jobcloud/jobcloud-closure-validator

此包已弃用且不再维护。未建议替代包。

Jobcloud 闭包验证器

3.0.0 2018-06-11 14:47 UTC

This package is not auto-updated.

Last update: 2022-01-14 22:48:08 UTC


README

Build Status Total Downloads Latest Stable Version Scrutinizer Code Quality

功能

检查闭包签名的简单验证器。

要求

PHP ~7.0

安装

通过 Composer 作为 jobcloud/jobcloud-closure-validator 安装。

用法

准备

use Jobcloud\ClosureValidator\Parameter;
use Jobcloud\ClosureValidator\Signature;
use Jobcloud\ClosureValidator\Validator;

$closure = function($param1, $param2) {};

$validator = new Validator;

$givenSignature = $validator->getSignatureFromClosure($closure);

$wishedSignature = new Signature(
    [
        new Parameter('param1'),
        new Parameter('param2')
    ]
);

差异

$diff = $validator->compare($givenSignature, $wishedSignature);

if (!$diff->isIdentical()) {
    throw new \Exception('Invalid closure signature');
}

有效或异常

$validator->validOrException($givenSignature, $wishedSignature);