25 lines
484 B
PHP
25 lines
484 B
PHP
<?php
|
|
|
|
namespace Lucent\Record;
|
|
|
|
use stdClass;
|
|
|
|
class Mapper
|
|
{
|
|
public function __construct(
|
|
public InputFormatter $inputFormatter
|
|
)
|
|
{
|
|
}
|
|
|
|
public function fromDB(stdClass $data): Record
|
|
{
|
|
$record = match (true) {
|
|
!empty($data->_file) => File::fromDB($data),
|
|
default => Document::fromDB($data),
|
|
};
|
|
|
|
$record->data = $this->inputFormatter->fill($record->schema, $record->data);
|
|
return $record;
|
|
}
|
|
} |