ModelFactory implements IModelFactory, IModelMapper
Builds models with service providers.
While this is a factory, it should only be used with a single model type.
Tags
Table of Contents
$setFactory | Property factory instance | IPropertySetFactory |
---|---|---|
$modelFactory | Data mapper for IModel instances | IModelMapper |
$propertySet | Property set used for all models | IPropertySet |
$serviceConfig | Map of property name => IPropertyConfig for any of the attached services | array |
$modelConfig | IModel Property config | \buffalokiwi\magicgraph\property\IPropertyConfig[] |
__construct() | Create a new Factory 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 |
getServiceConfigMap() | Retrieve the service configuration data as a map of property name => IPropertyConfig | array |
getServiceConfig() | Retrieve a specific config instance by property name. | IPropertyConfig |
createAndMap() | Maps a map of raw data (attribute => value) to an IModel instance. | IModel |
map() | Map some data to properties in some model. | void |
create() | Create a model and initialize any service provider backed properties | IModel |
getNewPropertySet() | IPropertySet | |
cleanExtraConfig() | mixed |
Properties
$setFactory
Property factory instance
private
IPropertySetFactory
$setFactory
$modelFactory
Data mapper for IModel instances
private
IModelMapper
$modelFactory
$propertySet
Property set used for all models
private
IPropertySet
$propertySet
$serviceConfig
Map of property name => IPropertyConfig for any of the attached services
private
array
$serviceConfig
$modelConfig
IModel Property config
private
\buffalokiwi\magicgraph\property\IPropertyConfig[]
$modelConfig
Methods
__construct()
Create a new Factory instance
public
__construct(
$modelConfig :
IPropertyConfig
, $modelFactory :
IModelMapper
, $setFactory :
IPropertySetFactory
, ...$services :
IPropertyServiceProvider
)
: mixed
Parameters
- $modelConfig : IPropertyConfig
IModel configuration data
- $modelFactory : IModelMapper
The data mapper used for creating new IModel instances
- $setFactory : IPropertySetFactory
- $services : IPropertyServiceProvider
Services used as a backing model for some property.
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
test(
...$models :
IModel
)
: void
Parameters
- $models : IModel
One or more models to test
Tags
getServiceConfigMap()
Retrieve the service configuration data as a map of property name => IPropertyConfig
public
getServiceConfigMap(
)
: array
Return values
array —config data.
getServiceConfig()
Retrieve a specific config instance by property name.
public
getServiceConfig(
$propertyName :
string
)
: IPropertyConfig
Parameters
- $propertyName : string
Property name
Tags
Return values
IPropertyConfig —Service provider config
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
This is unused within the model factory.
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
create()
Create a model and initialize any service provider backed properties
public
create(
$data :
array
[, $extraConfig :
array
= [] ]
, ...$baseConfig :
IPropertyConfig
)
: IModel
Parameters
- $data : array
- $extraConfig : array = []
Extra configuration data for creating other properties. If this is included, the cached property set is not used.
- $baseConfig : IPropertyConfig
Return values
IModelgetNewPropertySet()
private
getNewPropertySet(
$extraConfig :
array
, ...$baseConfig :
IPropertyConfig
)
: IPropertySet
Parameters
- $extraConfig : array
- $baseConfig : IPropertyConfig
Return values
IPropertySetcleanExtraConfig()
private
cleanExtraConfig(
$config :
array
)
: mixed
Parameters
- $config : array