Introduce explicit inputClass, outputClass, dataClass semantics on Metadata#8338
Draft
Cafeine42 wants to merge 1 commit into
Draft
Introduce explicit inputClass, outputClass, dataClass semantics on Metadata#8338Cafeine42 wants to merge 1 commit into
Cafeine42 wants to merge 1 commit into
Conversation
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.
Introduce explicit
inputClass,outputClass,dataClasssemantics onMetadataContext
Metadata::getClass()was used for many distinct purposes: fetching the entity/document class for Doctrine queries, the DTO for serialization, or the API resource class for IRI/routing. All three roles silently collapsed into one method, making it impossible to tell from a call site which concept was intended.What this PR does
Adds three new methods to
Metadata:getApiClass()— semantic alias forgetClass(). Signals "I want the API resource class", without changing behaviour.getDataClass()— returns the persistence class (entity, document, Eloquent model) fromstateOptions, falling back togetClass(). Implemented via a newDataOptionsInterfaceon Doctrine ORM/ODM and Eloquent Options.getInputClass()/getOutputClass()— return the DTO class for deserialization/serialization, falling back togetClass()when no explicit DTO is configured. Returnnullwheninput: false/output: false.All ~150
getClass()call sites across the codebase are replaced by whichever of the four is semantically correct.Open question: can
getApiClass()be eliminated?getApiClass()is currently a pure alias —return $this->class— introduced only to label usages ofgetClass()that didn't belong to input, output, or data. The question is whether those remaining usages could themselves be replaced.Looking at the places where
getApiClass()is still called:getApiClass()stays necessaryIriConverter)ResourceMetadataCollectionFactory::create())resource_classcontext keyResourceClassResolveruse it to identify which API resource is being processedSerializerContextBuildercomparisongetInputClass() === getApiClass()force_resource_class(stateOptions without explicit output)In all these cases the API resource class acts as a stable identifier — the thing that ties routing, metadata, IRI templates, and documentation together. It is structurally distinct from what comes in (
inputClass), what goes out (outputClass), and what is persisted (dataClass). SogetApiClass()cannot be eliminated today; it marks the boundary of the concept rather than a shortcut for one of the other three.A future step could be to remove
getClass()entirely, makinggetApiClass()the canonical name and forcing any remaining ambiguous callers to be explicit — but that is a separate breaking-change PR.