104corp/validation

A simple validation library.

1.2.1 2018-03-21 11:29 UTC

This package is not auto-updated.

Last update: 2024-11-01 07:26:16 UTC


README

Build Status codecov Latest Stable Version Total Downloads License

A simple validation library.

安裝套件

composer require 104corp/validation

使用方法

驗證元件使用方法很簡單,如果要驗證輸入是否為 string type 的話,可以這樣寫:

<?php

use Corp104\Validation\Facade;
use Corp104\Validation\Validators\StringType;

$pid = 123;

if (Facade::isValid(StringType::class, $pid)) {
    echo '格式正確';
} else {
    echo '格式不正確';
}

元件也提供簡單的斷言驗證方法:

<?php

use Corp104\Validator;
use Corp104\Validator\Validator\StringType;

$pid = 123;
$exception = new InvalidArgumentException('格式錯誤');

try {
    Facade::assert(StringType::class, $pid, $exception);
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();  // 顯示 '格式錯誤'
}

驗證器

目前實作如下:

Contributing

See CONTRIBUTING