mf / type-validator
TypeValidator 用于断言值类型
4.1.0
2022-01-14 13:44 UTC
Requires
- php: ^8.0
Requires (Dev)
- lmc/coding-standard: ^3.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.3
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
README
TypeValidator 用于断言值类型
目录
要求
- PHP 8.0
安装
composer require mf/type-validator
使用
$validator = new TypeValidator( TypeValidator::TYPE_STRING, TypeValidator::TYPE_INT, [TypeValidator::TYPE_STRING], [TypeValidator::INT] ); $validator->assertKeyType('string - value'); $validator->assertValueType(1); $validator->assertValueType('invalid value type'); // throws InvalidArgumentException
使用自定义异常
$validator = new TypeValidator( TypeValidator::TYPE_STRING, TypeValidator::TYPE_INT, [TypeValidator::TYPE_STRING], [TypeValidator::INT], App\MyCustomException::class ); $validator->assertKeyType('string - value'); $validator->assertValueType(1); $validator->assertValueType('invalid value type'); // throws App\MyCustomException