Slide 26
Slide 26 text
use App\Entity\Book as BookEntity;
use App\ValueObject\Book;
#[AsMapper(from: BookEntity::class, to: Book::class)]
class BookEntityToDtoMapper implements MapperInterface
{
public function load(object $from, string $toClass, array $context): object
{
$entity = $from;
return new Book($entity->getId());
}
public function populate(object $from, object $to, array $context): object
{
$to->id = (string) $from->getId();
$to->title = $from->getTitle();
return $to;
}
}
MicroMapper: The Tiny,
Underwhelming
Data Mapper for Symfony!
https://github.com/SymfonyCasts/micro-mapper