symfony / type-info
提取PHP类型信息。
v7.1.5
2024-09-19 21:48 UTC
Requires
- php: >=8.2
- psr/container: ^1.1|^2.0
Requires (Dev)
- phpstan/phpdoc-parser: ^1.0
- symfony/dependency-injection: ^6.4|^7.0
- symfony/property-info: ^6.4|^7.0
Conflicts
- phpstan/phpdoc-parser: <1.0
- symfony/dependency-injection: <6.4
- symfony/property-info: <6.4
This package is auto-updated.
Last update: 2024-09-21 06:12:38 UTC
README
TypeInfo组件用于提取PHP类型信息。
此组件为实验性。 实验性功能 不受 Symfony 的 向后兼容承诺 的保护。
入门
composer require symfony/type-info
composer require phpstan/phpdoc-parser # to support raw string resolving
<?php use Symfony\Component\TypeInfo\Type; use Symfony\Component\TypeInfo\TypeResolver\TypeResolver; // Instantiate a new resolver $typeResolver = TypeResolver::create(); // Then resolve types for any subject $typeResolver->resolve(new \ReflectionProperty(Dummy::class, 'id')); // returns an "int" Type instance $typeResolver->resolve('bool'); // returns a "bool" Type instance // Types can be instantiated thanks to static factories $type = Type::list(Type::nullable(Type::bool())); // Type instances have several helper methods $type->getBaseType() // returns an "array" Type instance $type->getCollectionKeyType(); // returns an "int" Type instance $type->getCollectionValueType()->isNullable(); // returns true