stratadox/hydration-mapper

v2.4 2018-05-06 15:59 UTC

This package is auto-updated.

Last update: 2024-03-29 03:57:37 UTC


README

Build Status Coverage Status Infection Minimum PhpStan Level Scrutinizer Code Quality Maintainability Latest Stable Version License

Implements Latest Stable Version License

Mapping builder for hydration purposes; maps array or array-like data structures to object properties, in order to assemble the objects that model a business domain.

Usage sample

<?php

$hydrator = Mapper::forThe(Book::class)
     ->property('title', Has::one(Title::class)
        ->with('title')
     )
     ->property('isbn', Has::one(Isbn::class)
         ->with('code', In::key('id'))
         ->with('version', Call::the(function ($data) {
             return strlen($data['id']);
         }))
     )
     ->property('author', Has::one(Author::class)
         ->with('firstName', In::key('author_first_name'))
         ->with('lastName', In::key('author_last_name'))
     )
     ->property('contents', Has::many(ChapterProxy::class)
         ->containedInA(Chapters::class)
         ->loadedBy(new ChapterLoaderFactory)
     )
     ->property('format')
     ->finish();

Installation

Install using composer:

composer require stratadox/hydration-mapper

More details

For more information, view the Hydrate repository