innmind/type

1.2.0 2024-02-17 08:56 UTC

This package is auto-updated.

Last update: 2024-09-17 10:14:14 UTC


README

Build Status codecov Type Coverage

此包允许将类型描述为对象,以检查给定的类型是否可以接受某个值,或者是否与另一个类型兼容。

安装

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