thorough-php / type-guard
PHP 类型验证器
v1.0
2019-03-09 20:06 UTC
Requires
- php: >=7.2
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: ^0.10.3
- phpunit/phpunit: ^7.3
This package is not auto-updated.
Last update: 2024-09-30 21:45:23 UTC
README
特性
TypeGuard 可以验证
- 标量类型:
string、integer等
(new TypeGuard('string'))->match('foo'); // => true
- 对象类型:
ArrayAccess、stdClass等
(new TypeGuard('stdClass'))->match(new stdClass()); // => true
- 联合类型:
string|integer
$guard = new TypeGuard('string|integer'); $guard->match('foo'); // => true $guard->match(1); // => true
- 交叉类型:
ArrayAccess&Countable
(new TypeGuard('ArrayAccess&Countable'))->match(new ArrayIterator()); // => true
- 可选类型:
?string
(new TypeGuard('?string'))->match(null); // => true