承接 symfony/type-info 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

symfony/type-info

最新稳定版本:v8.0.1

Composer 安装命令:

composer require symfony/type-info

包简介

Extracts PHP types information.

README 文档

README

The TypeInfo component extracts PHP types information.

Getting Started

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\TypeIdentifier;
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 classes have their specific methods
Type::object(FooClass::class)->getClassName();
Type::enum(FooEnum::class, Type::int())->getBackingType();
Type::list(Type::int())->isList();

// Every type can be cast to string
(string) Type::generic(Type::object(Collection::class), Type::int()) // returns "Collection<int>"

// You can check that a type (or one of its wrapped/composed parts) is identified by one of some identifiers.
$type->isIdentifiedBy(Foo::class, Bar::class);
$type->isIdentifiedBy(TypeIdentifier::OBJECT);
$type->isIdentifiedBy('float');

// You can also check that a type satifies specific conditions
$type->isSatisfiedBy(fn (Type $type): bool => !$type->isNullable() && $type->isIdentifiedBy(TypeIdentifier::INT));

Resources

统计信息

  • 总下载量: 40.27M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 190
  • 点击次数: 0
  • 依赖项目数: 55
  • 推荐数: 2

GitHub 信息

  • Stars: 190
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04