symfony/property-info
Symfony PropertyInfo component extracts metadata about PHP class properties—types, access, docs, and more—by reading popular sources like PHPDoc, reflection, and other metadata providers. Useful for serializers, validators, and API tooling.
The symfony/property-info package is a low-level, metadata-driven reflection tool designed to extract property information (types, mutability, docblocks, etc.) from PHP classes. It is not a high-level framework but rather a foundational component that aligns well with Laravel’s dependency injection (DI), validation, serialization (e.g., API Platform), and form handling systems.
Key Use Cases in Laravel:
@var, @psalm-type) and constructor/accessor-based types.Illuminate\Http\Request or custom form handlers).Misalignment Risks:
ReflectionClass). Useful only for metadata-heavy scenarios.get_object_vars() may suffice.| Integration Point | Feasibility | Notes |
|---|---|---|
| Validation (Laravel 10+) | High | Can resolve @var types for Illuminate\Validation\Rules or custom rules. |
| API Serialization | High | Works with API Platform, JMS Serializer, or custom JSON:API serializers. |
| Eloquent Attribute Casting | Medium | Useful for dynamic casting logic (e.g., resolving @cast annotations). |
| Form Request Binding | Medium | Can infer type hints for Illuminate\Validation\Validator rules. |
| Dependency Injection | Low | Not a direct replacement for Laravel’s container, but useful for metadata-driven DI. |
| GraphQL (Nexus/GraphQL PHP) | High | Can resolve input object types from docblocks. |
Example Integration Scenarios:
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
$extractor = new PropertyInfoExtractor([new PhpDocExtractor()], new PropertyTypeExtractor());
$type = $extractor->getTypes(MyModel::class, 'email');
// Resolves `@var string|null` → applies `required|string` validation.
$metadata = $extractor->getProperties(MyModel::class);
// Generates OpenAPI schema from `@OA\Property` or `@var` annotations.
| Risk Area | Severity | Mitigation |
|---|---|---|
| PHP Version Compatibility | Medium | Requires PHP 8.1+ (Laravel 10+). Symfony 8+ may need adjustments for older Laravel. |
| DocBlock Parsing Quirks | High | Some edge cases (e.g., inherited properties, generic types) may need custom extractors. |
| Performance Overhead | Medium | Reflection + docblock parsing is slower than native reflection. Cache results aggressively. |
| Dependency Conflicts | Low | phpdocumentor/reflection-docblock is a direct dependency—version conflicts possible. |
| Laravel-Specific Edge Cases | High | Magic properties (e.g., Eloquent accessors), dynamic properties (e.g., __get), or closures may break extraction. |
Critical Questions for TPM:
Validator + Rules suffice, or is dynamic metadata needed?Arrayable, JsonSerializable, or work alongside them?Illuminate\Support\Facades\Cache).PhpDocExtractor fails, should it degrade to ReflectionExtractor?ExtractorInterface implementation.get_object_vars() for critical paths.| Laravel Component | Compatibility | Integration Strategy |
|---|---|---|
| Validation (Validator) | High | Use PropertyInfoExtractor to dynamically resolve @var types for Rules. |
| API (Laravel API Tools) | High | Replace manual OpenAPI schema generation with auto-generated metadata. |
| Eloquent ORM | Medium | Extend CastsAttributes or MutatesAttributes to resolve docblock-based casting rules. |
| Form Requests | Medium | Use in Illuminate\Validation\Validator to infer type hints from docblocks. |
| Serialization (JSON:API) | High | Integrate with Spatie’s Laravel JSON:API or custom serializers for dynamic metadata. |
| GraphQL (Nexus) | High | Resolve input object types from @var annotations in GraphQL input types. |
| Dependency Injection | Low | Not a direct fit, but could enhance metadata for Container bindings. |
Phase 1: Proof of Concept (PoC)
PropertyInfoServiceProvider to bootstrap the component.@var types for a model).Phase 2: Core Integration
Illuminate\Validation\Rules\Type to use PropertyInfoExtractor.PropertyInfoCaster to resolve docblock-based attribute casting.Phase 3: Optimization & Caching
Illuminate\Support\Facades\Cache with a tagging system (e.g., model:MyModel).PhpStanExtractor if phpstan/extension-installer is present).Phase 4: Edge Case Handling
ExtractorInterface for Laravel-specific cases (e.g., Eloquent accessors).ReflectionProperty).| Compatibility Factor | Assessment |
|---|---|
| PHP Version | Requires PHP 8.1+ (Laravel 10+). Symfony 7/8 may need adjustments for older Laravel. |
| Laravel Version | Best fit for Laravel 10+ (due to PHP 8.1+ and Symfony 6+ dependencies). |
| Existing Packages | Conflicts possible with phpdocumentor/reflection-docblock (version pinning required). |
| Custom Logic | May need custom extractors for Laravel-specific features (e.g., Eloquent). |
Dependency Graph Conflicts:
phpdocumentor/reflection-docblock: Symfony 8+ requires v6, but some Laravel packages may use v5. Pin versions explicitly.symfony/property-access: Optional but useful for property writing checks (e.g., isWritable()).How can I help you explore Laravel packages today?