texdc/guard

具有可重用防护函数的断言库

v1.0.0 2017-10-17 05:39 UTC

This package is not auto-updated.

Last update: 2024-09-15 04:55:01 UTC


README

beberlei/assert的一个扩展,增加了额外的断言和一个工厂函数,以简化使用。

安装

composer require texdc/guard

使用

namespace my\lib;

use function texdc\guard\verify;

function storeRating(int $rating) : void {
    verify($rating)->numericRange(1, 10, 'rating should be from 1 - 10');
    // ...
}

function speak(string $message, ?int $times = null) : void {
    verify($message)->notEmpty('message is required')->length(256, 'message is too long');
    verify($times, 'invalid multiplier')->nullOr()->isModulus(8);
    // ...
}