mapper_interface
Interface Mapper.
Contract for Data Mappers that convert between Database Records (stdClass) and Domain Entities.
Table of Contents
Methods
- db_to_domain() : T
- Convert a raw DB record (and optional metadata) into a Domain Entity.
- domain_to_db() : stdClass
- Convert a Domain Entity into a raw DB record for persistence.
Methods
db_to_domain()
Convert a raw DB record (and optional metadata) into a Domain Entity.
public
db_to_domain(stdClass $record, array<string, mixed> $metadata) : T
Parameters
- $record : stdClass
-
The raw row from the database (e.g., from $DB->get_record)
- $metadata : array<string, mixed>
-
Key-value array of related metadata
Return values
T —The hydrated Domain Entity
domain_to_db()
Convert a Domain Entity into a raw DB record for persistence.
public
domain_to_db(T $entity) : stdClass
Note: This usually returns the record for the main table only.
Parameters
- $entity : T