Custom Types
This content is for v1.0. Switch to the latest version for up-to-date documentation.
Convert between PHP-specific values and database storage values.
TypeConverterInterface
Section titled “TypeConverterInterface”interface TypeConverterInterface{ public function convertToPHP(mixed $value): mixed; public function convertToDB(mixed $value): mixed;}Use a converter when the database representation is not the same shape as the PHP representation. Common examples are enums, value objects, booleans, dates, and geometry-like values.
Built-in converters
Section titled “Built-in converters”Articulate ships built-in mappings — bool ↔ TINYINT(1), int ↔ INT, float ↔ FLOAT, string ↔ VARCHAR(255), DateTimeInterface ↔ DATETIME — plus named converters for common cases:
BoolTypeConverterDateTimeTypeConverterPointTypeConverter
Custom class mappings and TypeConverterInterface cover complex types, with priority-based resolution when a class implements multiple interfaces with registered mappings.
Registration
Section titled “Registration”$typeRegistry->registerType('point', new PointTypeConverter());$typeRegistry->registerClassMapping(Point::class, 'point');Once registered, entity properties can use the type name through #[Property(type: 'point')] or class mapping.
public function setStatus(ProductStatus $status): void{ $this->status = (new ProductStatusConverter())->convertToDatabase($status);}
public function statusEnum(): ProductStatus{ return (new ProductStatusConverter())->convertToPHP($this->status);}