feat(metadata): allow extending the Link attribute - #8536
Merged
Merged
Conversation
Link was the only final subclass of Parameter, preventing users from naming a recurring link shape as a domain attribute. Attribute arguments must be constant expressions, so a static factory is not a workaround. All Link withers use `clone $this`, so subclassing is safe. LinkFactory now matches Link attributes with IS_INSTANCEOF, otherwise a subclassed attribute on a property would be silently ignored. Closes api-platform#8449
soyuka
added a commit
that referenced
this pull request
Sep 16, 2026
The 4.4 branch reverts #8211 (constraint-aware 422 for denormalization errors) so that 4.4.0 ships the 4.3 behaviour. That revert is deliberately not propagated here: 5.0 keeps the feature. Every file touched by the revert, by the ^4.4 constraint bump and by the deprecation-message fix was resolved to main's version. Only #8536 and the consolidated v4.4.0 changelog section come from 4.4.
Contributor
|
Thanks |
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.
Linkwas the onlyfinalsubclass of the abstractParameter—QueryParameterandHeaderParameterare both extendable. That prevents users from giving a recurring link shape a domain name:A static factory is not a workaround: attribute arguments must be constant expressions, and while
newhas been allowed there since PHP 8.1, static calls are not.Dropping
finalis safe — every wither onLinkusesclone $this, so a subclass survives them, and consumers (LinksHandlerTrait,IdentifiersExtractor,UriVariablesConverter) only read it through its getters.LinkFactory::createLinksFromAttributes()needed the matching half of the change: it looked up property attributes withgetAttributes(Link::class), which filters on the exact class name, so a subclassed attribute placed on a property would have been silently ignored. It now passes\ReflectionAttribute::IS_INSTANCEOF. No class in the tree extendsLink, so this is a no-op for existing code.Covered by
LinkFactoryTest::testCreateLinksFromAttributesWithExtendedLink, which asserts the subclass instance survives the factory and keeps the values its constructor preset.