[ * 'content' => $p->text, * 'published_at' => $p->createdAt, * ], * toRecordData: fn(PostModel $m) => [ * 'text' => $m->content, * 'createdAt' => $m->published_at->toIso8601String(), * ], * ); * * $registry->register($mapper); * * @template TSchema of Data * @template TModel of Model * * @extends RecordMapper */ class SchemaMapper extends RecordMapper { /** * @param class-string $schemaClass The atp-schema generated class * @param class-string $modelClass The Eloquent model class * @param Closure(TSchema): array $toAttributes Convert schema to model attributes * @param Closure(TModel): array $toRecordData Convert model to record data */ public function __construct( protected string $schemaClass, protected string $modelClass, protected Closure $toAttributes, protected Closure $toRecordData, ) {} public function recordClass(): string { return $this->schemaClass; } public function modelClass(): string { return $this->modelClass; } protected function recordToAttributes(Data $record): array { return ($this->toAttributes)($record); } protected function modelToRecordData(Model $model): array { return ($this->toRecordData)($model); } }