Symfony PropertyInfo

Extracts PHP class property types, docs, and read/write info by combining reflection, PHPDoc, and Doctrine metadata.

Library
Composer
vv8.1.4
2,221stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
84/100Excellent
Development Activity88
Maintenance92
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture85
Code Quality84
Innovation72
Learning Curve68

PropertyInfo answers a question that comes up constantly in serializers, form builders, and API generators: “what type is this property, is it readable/writable, and what does its docblock say?” Rather than picking one metadata source, it defines a set of extractor interfaces (type, description, access, initializable, list) and ships concrete extractors for reflection (ReflectionExtractor), PHPDoc comments (PhpDocExtractor, PhpStanExtractor), constructor promotion (ConstructorExtractor), and the Serializer component’s own metadata (SerializerExtractor).

A PropertyInfoExtractor composes any number of these extractors and queries them in order until one returns an answer, so consumers get a single unified API regardless of how a given codebase documents its types — native PHP type hints, @var/@param docblocks, or Doctrine/Serializer annotations. It’s a foundational piece behind Symfony’s Serializer, Form, and API Platform’s schema generation.

What You Get

  • A PropertyInfoExtractorInterface with focused sub-interfaces for type (PropertyTypeExtractorInterface), description (PropertyDescriptionExtractorInterface), access (PropertyAccessExtractorInterface), and initializability (PropertyInitializableExtractorInterface)
  • Concrete extractors: ReflectionExtractor (native type hints and getter/setter conventions), PhpDocExtractor/PhpStanExtractor (docblock type parsing), ConstructorExtractor (promoted constructor properties), and SerializerExtractor (Symfony Serializer metadata)
  • A composing PropertyInfoExtractor that chains multiple extractors and returns the first non-null answer, plus PropertyInfoCacheExtractor to cache results for production performance
  • PropertyReadInfo/PropertyWriteInfo value objects describing exactly how a property is read (public property, getter, __get) or written (public property, setter, constructor, __set)

Common Use Cases

  • Powering Symfony Serializer’s normalize/denormalize type resolution so it knows what type to cast incoming JSON/XML data into
  • API Platform and similar API-generation tools that need per-property type/description metadata to build OpenAPI schemas automatically
  • Form component type-guessing, inferring a form field type from a bound object’s property types without manual configuration
  • Any tool doing PHP object introspection (admin generators, GraphQL schema builders) that needs a single reliable source of truth for a property’s type across mixed docblock/native-type codebases

Under The Hood

Architecture — The component is built around a small interface segregation: each concern (type, description, access, initializable, list) has its own interface, and each extractor implements only the ones it supports. PropertyInfoExtractor (98 lines) is the composition root — it holds ordered lists of extractors per concern and iterates them, returning the first non-null result, which lets consumers register custom extractors without touching the built-ins. PropertyInfoCacheExtractor wraps any extractor with a PSR-6 cache to avoid repeated reflection/docblock parsing in production. Tech Stack — Pure PHP (>=8.4.1 for this HEAD version), depending on symfony/string and the newer symfony/type-info component for type representation; dev dependencies include phpdocumentor/reflection-docblock and phpstan/phpdoc-parser for docblock-based extractors, plus optional integration with symfony/cache, symfony/dependency-injection, and symfony/serializer. Code Quality — 66 test files cover each extractor independently plus the composing PropertyInfoExtractor; as a core Symfony component it maintains a documented CHANGELOG, typed properties/return types throughout, and sees consistent commit activity (~5/month) reflecting active maintenance rather than a frozen legacy component. API Design — The extractor-interface pattern is the standout design choice: rather than one monolithic “get me the type” function, each concern is a separate, independently implementable interface, so a consumer (or a custom extractor) only needs to implement the sub-interfaces it cares about, and PropertyInfoExtractor handles composing them into the single-call API most consumers actually want.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search