czproject / assert
断言辅助工具。
v1.5.0
2023-07-11 17:03 UTC
Requires
- php: >=5.6.0
Requires (Dev)
- nette/tester: ^2.0
README
断言辅助工具,抛出异常。
安装
composer require czproject/assert
CzProject\Assert
需要 PHP 5.6.0 或更高版本。
使用
use CzProject\Assert\Assert; function add($a, $b) { Assert::int($a); Assert::int($b); return $a + $b; }
assert($value, $msg = NULL)
- 检查值是否为TRUE
bool($value, $msg = NULL)
- 检查值是否为bool
int($value, $msg = NULL)
- 检查值是否为int
intOrNull($value, $msg = NULL)
- 检查值是否为int|NULL
float($value, $msg = NULL)
- 检查值是否为float
floatOrNull($value, $msg = NULL)
- 检查值是否为float|NULL
number($value, $msg = NULL)
- 检查值是否为float|int
numberOrNull($value, $msg = NULL)
- 检查值是否为float|int|NULL
string($value, $msg = NULL)
- 检查值是否为string
stringOrNull($value, $msg = NULL)
- 检查值是否为string|NULL
type($value, $type, $msg = NULL)
- 检查值是否为给定类型的实例typeOrNull($value, $type, $msg = NULL)
- 检查值是否为给定类型的实例或NULL
null($value, $msg = NULL)
- 检查值是否为NULL
in($value, $arr, $msg = NULL)
- 检查值是否在数组中inArray($value, $arr, $msg = NULL)
-Assert::in()
的别名
PhpStan 扩展
services: - class: CzProject\Assert\Bridges\PhpStan\StaticMethodTypeSpecifyingExtension tags: - phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension
许可证: 新BSD许可证
作者: Jan Pecha, https://www.janpecha.cz/