104corp / validation
A simple validation library.
Installs: 43 149
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 1
Open Issues: 1
Requires
- php: >=5.5
Requires (Dev)
- phpunit/phpunit: >=4.8 <6
- squizlabs/php_codesniffer: ^3.2
This package is not auto-updated.
Last update: 2024-11-01 07:26:16 UTC
README
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(); // 顯示 '格式錯誤' }
驗證器
目前實作如下:
Corp104\Validation\Validators\Ip
Corp104\Validation\Validators\StringType
Corp104\Validation\Validators\TraversableType
Corp104\Validation\Validators\Utf8String
Contributing
See CONTRIBUTING 。