-
-
Notifications
You must be signed in to change notification settings - Fork 138
feat(mapper): support contextual serializers and casters #1791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
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
1ee7bde to
a026a63
Compare
Member
Author
|
This is ready for an initial review! What do we think about this approach? |
innocenzi
commented
Dec 9, 2025
brendt
requested changes
Dec 10, 2025
Member
Author
|
@brendt ready for another review! |
9b83f8f to
c848c21
Compare
…ableCaster` and `ConfigurableSerializer`
c848c21 to
23a8db6
Compare
23a8db6 to
55fd009
Compare
brendt
approved these changes
Dec 11, 2025
innocenzi
added a commit
that referenced
this pull request
Dec 11, 2025
brendt
pushed a commit
that referenced
this pull request
Dec 12, 2025
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.
Depends on #1789
Closes #1522
This pull requests adds the concept of contexts to casters and serializers. It works by adding the ability to the mapper to use a context (string, enum or
Contextclass that might hold data).The mapper will inject the context to serializers/casters/mappers when resolved from the container, and will use serializers/casters registered for that context (or fall back to the default context).
This allows, for instance, the database to use dedicated serializers/casters. Before this pull request, we had to manually add a condition for boolean values to be transformed properly depending on the current database dialect. After this PR, this functionality works through a serializer:
Serializers and casters are now discovered by Discovery instead of being registered through an initializer. Since ordering is important for them, they support priority ordering through
Tempest\Core\Priority.It's also possible for userland to register their own casters and serializers this way. To use a specific context, we use the
inmethod onObjectFactory(orSerializerFactoryorCasterFactory):To pass data to a caster/serializer/mapper, an object extending
Contextmay be used instead of a string/enum. The database package now uses aDatabaseContextunder the hood:As seen above, the
BooleanSerializerexpects aDatabaseContextin its constructor. Note that for now, the injection works by parameter name, not parameter type.