Download the PHP package tonicforhealth/model-transformer without Composer
On this page you can find all versions of the php package tonicforhealth/model-transformer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tonicforhealth/model-transformer
More information about tonicforhealth/model-transformer
Files in tonicforhealth/model-transformer
Package model-transformer
Short Description Simple abstraction for object transformations
License MIT
Informations about the package model-transformer
Model Transformer
Simple abstraction for object transformations.
Installation
Require dependencies via composer:
Usage
Possible use cases:
- Separate domain model layer from view or presentation layer, but still keep objects.
- Separate domain model from resource representations (in RESTful applications).
Suppose, there are two domain objects:
And one presentation object which can be used in presentation layer:
There are lot of solutions for transforming Product
and Category
objects to ProductRepresentation
:
- just create
ProductRepresentation
basedProduct
andCategory
on at the needed place; - create factory for
ProductRepresentation
; - and so on.
This library provides simple and concise solution for this problem:
- Create transformer for objects.
- Register it in transformer manager or use it separately.
Possible transformer for ProductRepresentation
:
Register it:
With an optional priority integer (higher equals more important and therefore that the transformer will be triggered earlier) that determines when a transformer is triggered versus other transformers (defaults to 0).
Use it anywhere:
If you have simple rules of transformation, you can use ObjectTransformerInterface instead. As bonus transformation will work much faster.
Specifications
All actual documentation is runnable library specifications at /spec
directory.
And to ensure library is not broken, run (under library directory):