fix(metadata): apply YAML/XML attributes to virtual (method-backed) properties#8220
Merged
soyuka merged 1 commit intoJun 2, 2026
Merged
Conversation
ExtractorPropertyMetadataFactory short-circuited to handleNotFound() when the resource class did not declare a PHP property matching the requested name. YAML and XML mappings are free to declare virtual properties backed by methods (e.g. `admin` mapped to isAdmin()), and ExtractorPropertyNameCollection- Factory already exposes them, so the guard silently dropped configured metadata (security expressions, descriptions, etc.). Remove the property_exists/interface_exists clause: the remaining `extractor->getProperties()[$resourceClass][$property] ?? null` already returns null when the property is not in the extracted mapping, falling through to handleNotFound(). Closes api-platform#8178
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ExtractorPropertyMetadataFactory::create()short-circuited tohandleNotFound()whenever the resource class did not declare a real PHP property matching the requested name:YAML and XML mappings can legitimately declare virtual properties backed by methods — e.g.
adminmapped toisAdmin()— andExtractorPropertyNameCollectionFactoryalready surfaces those names. The guard silently dropped configured metadata (security expressions, descriptions, IRIs, …) for any such property. PHP#[ApiProperty]attributes worked because they bypass this factory.The remaining null-coalesce on the extractor lookup already provides the correct fallback to
handleNotFound()when the property is not in the extracted mapping, so theproperty_existsclause is redundant for real PHP properties and incorrect for virtual ones.Truth table after the change:
?? null)?? null)Only the third row changes.
Closes #8178
Test plan
ExtractorPropertyMetadataFactoryTest::testCreateVirtualPropertyFromExtractor— fails before the fix withPropertyNotFoundException: Property "admin" of the resource class … not found., green after.src/Metadata/Tests/Propertysuite green (37/37).PropertyMetadataCompatibilityTest(YAML + XML) still green.