Documentation

IModel extends IteratorAggregate

Defines a model.

Tags
todo

Write documentation

Table of Contents

createCopy() Create a copy/clone of the model and all properties. IModel
clearEditFlags() Clears the internal edited flags for each property void
instanceOf() A way to determine if this model OR if a property set is an instance of some interface. bool
hasEdits() Detect if any properties have been edited in this model bool
getPropertySet() Retrieve the property set used for this model. IPropertySet
getPropertyNameSetByFlags() Retrieve a set with the property name bits toggled on for properties with the supplied flags. IBigSet
getPropertyConfig() Retrieve a property config instance attached to this model. IPropertyConfig
getPropertyNameSet() Retrieve property names as an IBigSet instance. IBigSet
toObject() Convert the model to a json representation. string
toArray() Convert this model to an array. array
fromArray() void
equals() Test if this model is equal to some other model bool
getValue() Retrieve the value of some property mixed
setValue() Sets the value of some property void
getModifiedProperties() Retrieve a list of modified properties ISet
getInsertProperties() Gets A propertyset containing properties for insert IBigSet
validate() Test to see if this model is valid prior to save() void
validateAll() If you want to validate each property and return a list of errors indexed by property name, this is the method to call. array
hash() Retrieve a unique hash for this object string
hasPrimaryKeyValues() Test that the model has all primary key values bool

Methods

createCopy()

Create a copy/clone of the model and all properties.

public createCopy( [ $copyIsSaveable : bool = true ] ) : IModel
Parameters
$copyIsSaveable : bool = true

If this is false, then the primary key flags are removed from the copied model. This will cause the repository save method to fail when a save is attempted.

Return values
IModel

Copied model

clearEditFlags()

Clears the internal edited flags for each property

public clearEditFlags( ) : void

instanceOf()

A way to determine if this model OR if a property set is an instance of some interface.

public instanceOf( $interface : string ) : bool

This is used due to decorators.

Parameters
$interface : string

Interface name

Return values
bool

if this implements it

hasEdits()

Detect if any properties have been edited in this model

public hasEdits( [ $prop : string = '' ] ) : bool
Parameters
$prop : string = ''

Property name. If $prop is not empty then this would test that the supplied property name is not empty. Otherwise, this tests if any property was edited.

Return values
bool

has edits

getPropertySet()

Retrieve the property set used for this model.

public getPropertySet( ) : IPropertySet

This method FORMERLY returned a clone of the internal property set. Currently, this returns the internal PropertySet.

Tags
reutrn

IPropertySet properties

Return values
IPropertySet

getPropertyNameSetByFlags()

Retrieve a set with the property name bits toggled on for properties with the supplied flags.

public getPropertyNameSetByFlags( ...$flags : string ) : IBigSet
Parameters
$flags : string

Flags

Return values
IBigSet

names

getPropertyConfig()

Retrieve a property config instance attached to this model.

public getPropertyConfig( $intf : string ) : IPropertyConfig
Parameters
$intf : string

Interface of the config instance

Tags
throws
Exception

if The requested interface was not used to build this model.

Return values
IPropertyConfig

The config instance

getPropertyNameSet()

Retrieve property names as an IBigSet instance.

public getPropertyNameSet( ) : IBigSet

This will return a set containing all of the property names, and have zero members active. This is available due to how expensive cloning the backing IPropertySet instance can be. Use this for simple operations such as determining if a property name is valid.

Return values
IBigSet

property names

toObject()

Convert the model to a json representation.

public toObject( [ $properties : IBigSet|null = null ] [, $includeArrays : bool = false ] [, $includeModels : bool = false ] ) : string
Parameters
$properties : IBigSet|null = null
$includeArrays : bool = false
$includeModels : bool = false
Return values
string

JSON object

toArray()

Convert this model to an array.

public toArray( [ $properties : IPropertySet = null ] [, $includeArrays : bool = false ] [, $includeModels : bool = false ] ) : array
Parameters
$properties : IPropertySet = null

Properties to include

$includeArrays : bool = false
$includeModels : bool = false
Return values
array

fromArray()

public fromArray( $data : array ) : void
Parameters
$data : array

equals()

Test if this model is equal to some other model

public equals( $that : IModel ) : bool
Parameters
$that : IModel

model to compare

Return values
bool

is equals

getValue()

Retrieve the value of some property

public getValue( $property : string [, $context : array = [] ] ) : mixed
Parameters
$property : string

Property

$context : array = []
Tags
throws
InvalidArgumentException

if the property is invalid

Return values
mixed

value

setValue()

Sets the value of some property

public setValue( $property : string , $value : mixed ) : void
Parameters
$property : string

Property to set

$value : mixed

property value

Tags
throws
InvalidArgumentException

if the property is invalid

getModifiedProperties()

Retrieve a list of modified properties

public getModifiedProperties( ) : ISet
Return values
ISet

modified properties

getInsertProperties()

Gets A propertyset containing properties for insert

public getInsertProperties( ) : IBigSet
Return values
IBigSet

insert properties

validateAll()

If you want to validate each property and return a list of errors indexed by property name, this is the method to call.

public validateAll( [ $debugErrors : bool = false ] ) : array

Note: This simply calls validate() in a loop, catches exceptions and tosses some errors in a list.

Parameters
$debugErrors : bool = false
Return values
array

[property name => message]

hash()

Retrieve a unique hash for this object

public hash( ) : string
Return values
string

hash

hasPrimaryKeyValues()

Test that the model has all primary key values

public hasPrimaryKeyValues( ) : bool
Return values
bool

has values

Search results