DefaultModelMapper implements IModelMapper
Used for setting model properties.
Maps property names and values to a model.
This should only be used with a single object type. ie: one mapper per repository.
Table of Contents
$createModel | Create model supplier | Closure |
---|---|---|
$clazz | Class/interface name of models | string |
__construct() | Create a new DefaultModelMapper instance | mixed |
getClass() | Retrieve the class or interface name this mapper works with. | string |
test() | Test that the supplied model implements the interface or class name returned by getClass(). | void |
createAndMap() | Maps a map of raw data (attribute => value) to an IModel instance. | IModel |
map() | Map some data to properties in some model. | void |
createModel() | Call the create model callback and return the results | IModel |
Properties
$createModel
Create model supplier
private
Closure
$createModel
$clazz
Class/interface name of models
private
string
$clazz
Methods
__construct()
Create a new DefaultModelMapper instance
public
__construct(
$createModel :
Closure
, $clazz :
string
)
: mixed
Parameters
- $createModel : Closure
A supplier that returns an IModel instance. f( ?IPropertySet $propertySet, array $data ) : IModel
- $clazz : string
A fully qualified class or interface name. All operations inside an IRepository will be locked to this type.
Tags
Return values
mixedgetClass()
Retrieve the class or interface name this mapper works with.
public
getClass(
)
: string
Return values
string —name
test()
Test that the supplied model implements the interface or class name returned by getClass().
public
final test(
...$models :
IModel
)
: void
Parameters
- $models : IModel
One or more models to test
Tags
createAndMap()
Maps a map of raw data (attribute => value) to an IModel instance.
public
createAndMap(
$data :
array
[, $propertySet :
IPropertySet|null
= null ]
)
: IModel
Parameters
- $data : array
data to map
Optionally accepts an IPropertySet instance. Supplied if passed to the IModelMapper constructor. f( ?IPropertySet $propertySet, array $data ) : IModel
- $propertySet : IPropertySet|null = null
An optional property set. If this is passed, then the supplied IPropertySet is passed to the $createModel Closure as the first argument.
Tags
Return values
IModel —model instance
map()
Map some data to properties in some model.
public
map(
$model :
IModel
, $data :
array
)
: void
Invalid properties are silently ignored.
Parameters
- $model : IModel
Model to push data into
- $data : array
data to push
createModel()
Call the create model callback and return the results
private
createModel(
[ $propertySet :
IPropertySet|null
= null ]
[, $data :
array
= [] ]
)
: IModel
Optionally accepts an IPropertySet instance. Supplied if passed to the IModelMapper constructor. $data is the raw data to be mapped to the model. f( ?IPropertySet $propertySet = null, array $data = [] ) : IModel
Parameters
- $propertySet : IPropertySet|null = null
An optional property set. If this is passed, then the supplied IPropertySet is passed to the $createModel Closure as the first argument.
- $data : array = []
Tags
Return values
IModel —new model instance