innmind / type
1.2.0
2024-02-17 08:56 UTC
Requires
- php: ~8.2
Requires (Dev)
- innmind/black-box: ~5.1
- innmind/coding-standard: ~2.0
- vimeo/psalm: ~5.13
This package is auto-updated.
Last update: 2024-09-17 10:14:14 UTC
README
此包允许将类型描述为对象,以检查给定的类型是否可以接受某个值,或者是否与另一个类型兼容。
安装
composer require innmind/type
用法
use Innmind\Type\{ Build, Primitive, }; final class Example { private int $id; } $type = Build::fromReflection((new \ReflectionProperty(Example::class, 'id'))->getType()); $type->allows(42); // true $type->allows('some-uuid'); // false $type->accepts(Primitive::int()); // true $type->accepts(Primitive::string()); // false