mf / type-validator
TypeValidator for asserting types of values
Installs: 35 064
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
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 for asserting types of values
Table of Contents
Requirements
- PHP 8.0
Installation:
composer require mf/type-validator
Usage
$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
With Custom Exception
$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