[PR #10313] Add TypedFieldMapper for automatic mapping of typed PHP fields to DBAL types #12266

Closed
opened 2026-01-22 16:13:30 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/10313

State: closed
Merged: Yes


This is an alternative implementation of https://github.com/doctrine/orm/pull/10290, fixes https://github.com/doctrine/orm/issues/9561

Previously, only a predefined set of automatic mappings was allowed for as array, bool, int, float, string, DateTime, DateTimeImmutable and DateInterval.

With this extension, it is possible to supply custom TypedFieldMapper implementation. Its validateAndComplete takes as parameter the ReflectionProperty of a given field and decides the appropriate mapping.

A new configuration option was added to set and get the TypedFieldMapper.

The old logic was moved into a class DefaultTypedFieldMapper which is used by default when no mapper is supplied.

The selected TypedFieldMapper is passed into ClassMetadataInfo's constructor. If empty, the DefaultTypedFieldMapper is used.

There is also ChainTypedFieldMapper class which allows chaining multiple TypedFieldMappers and apply them in a cascade (always if a field gets type assigned by the earlier mapper in the list, it will not be changed later).

Documentation has been updated to explain the new features. Tests were added to cover the new classes as well as ClassMetadataInfo and all mapping drivers.

**Original Pull Request:** https://github.com/doctrine/orm/pull/10313 **State:** closed **Merged:** Yes --- This is an alternative implementation of https://github.com/doctrine/orm/pull/10290, fixes https://github.com/doctrine/orm/issues/9561 Previously, only a predefined set of automatic mappings was allowed for as `array`, `bool`, `int`, `float`, `string`, `DateTime`, `DateTimeImmutable` and `DateInterval`. With this extension, it is possible to supply custom `TypedFieldMapper` implementation. Its `validateAndComplete` takes as parameter the ReflectionProperty of a given field and decides the appropriate mapping. A new configuration option was added to set and get the `TypedFieldMapper`. The old logic was moved into a class `DefaultTypedFieldMapper` which is used by default when no mapper is supplied. The selected `TypedFieldMapper` is passed into `ClassMetadataInfo`'s constructor. If empty, the `DefaultTypedFieldMapper` is used. There is also `ChainTypedFieldMapper` class which allows chaining multiple `TypedFieldMappers` and apply them in a cascade (always if a field gets type assigned by the earlier mapper in the list, it will not be changed later). Documentation has been updated to explain the new features. Tests were added to cover the new classes as well as `ClassMetadataInfo` and all mapping drivers.
admin added the pull-request label 2026-01-22 16:13:30 +01:00
admin closed this issue 2026-01-22 16:13:31 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#12266