class item_mapper extends abstract_mapper

internal  
 

Item mapper for domain items.

Responsible for converting between:

  • DB record (stdClass) + Meta Array → Domain Item Entity
  • Domain Item Entity → DB record (stdClass)
  • Domain Item + DTO → New Domain Item (Immutable update)

No business logic should exist here — this class performs pure data mapping.

Methods

db_to_domain(stdClass $record, array $metadata)

Convert from DB record (with metadata) to a Domain Item.

domain_to_db(entity_interface $entity)

Convert from domain item to DB record (stdClass).

apply_dto(item_interface $old, item_dto $dto)

Apply DTO onto an existing domain item, returning a cloned immutable copy.

Details

at line 53
entity_interface db_to_domain(stdClass $record, array $metadata)

Convert from DB record (with metadata) to a Domain Item.

Parameters

stdClass $record

The raw row from the database (e.g., from $DB->get_record)

array $metadata

Key-value array of related metadata

Return Value

entity_interface

The hydrated Domain Entity

Exceptions

coding_exception

at line 98
stdClass domain_to_db(entity_interface $entity)

Convert from domain item to DB record (stdClass).

Note: does NOT map metadata, as that is stored in a separate table.

Parameters

entity_interface $entity

Return Value

stdClass

at line 138
item_interface apply_dto(item_interface $old, item_dto $dto)

Apply DTO onto an existing domain item, returning a cloned immutable copy.

Parameters

item_interface $old

Existing item to be cloned

item_dto $dto

DTO with updated values

Return Value

item_interface

New immutable item with merged data

Exceptions

coding_exception