thorough-php / type-guard

PHP 类型验证器

v1.0 2019-03-09 20:06 UTC

This package is not auto-updated.

Last update: 2024-09-30 21:45:23 UTC


README

Build Status Coverage Status License: MIT PHPStan

特性

TypeGuard 可以验证

  • 标量类型:stringinteger
(new TypeGuard('string'))->match('foo'); // => true
  • 对象类型:ArrayAccessstdClass
(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