-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Feature Request
What
Allow Custom Types to access field mapping metadata (like options or a new class parameter) in convertToPHPValue() and convertToDatabaseValue().
Example usage:
#[ORM\Column(type: 'string_vo', class: Firstname::class)]
private Firstname $firstName;
#[ORM\Column(type: 'string_vo', class: Email::class)]
private Email $email;Why
Currently, creating Value Objects requires one Custom Type per class, even when the conversion logic is identical (string ↔ VO with __toString()).
The enumType parameter solves this elegantly for enums, but there's no equivalent for custom objects.
This leads to:
- Boilerplate: dozens of nearly identical Type classes
- Configuration overhead: one YAML entry per VO
- Maintenance burden: any change must be replicated across all types
A generic approach would allow a single StringValueObjectType to handle all string-based Value Objects, similar to how enumType works.
How
Pass field mapping metadata to Type methods:
public function convertToPHPValue(
mixed $value,
AbstractPlatform $platform,
array $fieldMapping = [] // New optional parameter
): mixed {
$class = $fieldMapping['class'] ?? null;
if ($class && $value !== null) {
return new $class($value);
}
return $value;
}Alternatively, introduce a dedicated parameter like valueObjectClass similar to enumType.
This would maintain backward compatibility while enabling generic Type implementations for Value Objects.