Documentation

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
todo

This might be expensive to run. This will need testing.

todo

figure out how to remove this.

deprecated

Replaced by ServiceableRepository and ServiceableModel

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

$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
mixed

getClass()

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
throws
Exception

if the model does not implement the interface.

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
throws
InvalidArgumentException

if the config is not listed by the specified property name.

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
throws
Exception

if the create model callback does not return an instance of IModel

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
IModel

cleanExtraConfig()

private cleanExtraConfig( $config : array ) : mixed
Parameters
$config : array
Return values
mixed

Search results