jobcloud/jobcloud-closure-validator

Jobcloud Closure Validator

3.0.0 2018-06-11 14:47 UTC

README

Build Status Total Downloads Latest Stable Version Scrutinizer Code Quality

Features

A simple validator to check closure signatures.

Requirements

PHP ~7.0

Installation

Through Composer as jobcloud/jobcloud-closure-validator.

Usage

Prepare

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

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

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

Valid or exception

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