\Gishiki\Core\MVC\ModelActiveRecord

Provides basic implementation of an object that are eligible for CRUD operations inside a database.

Summary

Methods
Properties
Constants
__construct()
save()
delete()
load()
getObjectID()
getReferenceID()
set()
get()
No public properties found
No constants found
No protected methods found
$structure
$database
N/A
getTableDefinition()
initSchema()
loadTable()
loadFields()
loadField()
loadRelation()
getPrimaryKeyName()
getCollectionName()
initTransitionSchema()
executeFilters()
executeFilter()
$typeMap
$transformations
$filters
$collection
$primaryKey
$changes
N/A

Properties

$structure

$structure : array

Type

array — the structure descriptor

$typeMap

$typeMap : 

Type

$transformations

$transformations : array

Type

array — the matrix of transformation of model_entry_key => db_row_name

$filters

$filters : array<mixed,\Closure>

Type

array<mixed,\Closure> — the collection of function to be executed to cast each model_entry_key in a correct value

$collection

$collection : string

Type

string — the name of the table/collection that will hold current model data

$primaryKey

$primaryKey : string

Type

string — the name (model wise) of the primary key (if any)

$changes

$changes : array<mixed,string>

Type

array<mixed,string> — the list of property changed

Methods

__construct()

__construct(\Gishiki\Database\DatabaseInterface  $connection) 

Create a new object.

Parameters

\Gishiki\Database\DatabaseInterface $connection

the database connection to be used

save()

save() 

Save the object instance to the database.

This function automatically performs create or update, based on data availability within the database.

delete()

delete() 

Delete the object from the database.

Does nothing if the object is not currently stored.

getObjectID()

getObjectID() : integer|null

Return the current object ID, as it is used within the database.

Returns

integer|null —

the current object ID, as it is used within the database, or null if the object is not stored.

getReferenceID()

getReferenceID() : integer

Return the current object ID.

Exactly as getObjectID(), this function also ensure an ID is returned, and if it is not a save() operation will be performed, in order to generate that ID.

Returns

integer —

the current object ID, as it is used within the database

set()

set(  $key,   $value) 

Parameters

$key
$value

get()

get(  $key,   $default = null) 

Parameters

$key
$default

getTableDefinition()

getTableDefinition() 

loadTable()

loadTable() 

Load the table definition from the static::$structure array.

Throws

\Gishiki\Core\MVC\Model\ActiveRecordException

the exception preventing data to be parsed correctly

loadFields()

loadFields(\Gishiki\Database\Schema\Table  $table) 

Load all fields inside the table from the static::$structure array.

Parameters

\Gishiki\Database\Schema\Table $table

the table structure to be finalized with fields

Throws

\Gishiki\Core\MVC\Model\ActiveRecordException

the exception preventing data to be parsed correctly

loadField()

loadField(\Gishiki\Database\Schema\Table  $table, array  $fieldDefinition, string  $fieldName = null) 

Load a field inside the table from the static::$structure array.

Parameters

\Gishiki\Database\Schema\Table $table

the table structure to be finalized with fields

array $fieldDefinition

the field definition

string $fieldName

the short name for the column

Throws

\Gishiki\Core\MVC\Model\ActiveRecordException

the exception preventing data to be parsed correctly

loadRelation()

loadRelation(\Gishiki\Database\Schema\Column  $column, string  $className, string  $propName) 

Load a relation to another class.

If the given class is not registered attempt to register it by loading its table structure definition.

Parameters

\Gishiki\Database\Schema\Column $column

the column to be updated with the given relation

string $className

the name of the ActiveRecord class

string $propName

the name of the property to be used

Throws

\Gishiki\Core\MVC\Model\ActiveRecordException

the exception preventing relation to be created

getPrimaryKeyName()

getPrimaryKeyName() : string

Get the name of the primary key field.

Returns

string —

the name of the primary key

getCollectionName()

getCollectionName() : string

Get the name of the table or collection that will hold data.

Returns

string —

the collection name

initTransitionSchema()

initTransitionSchema() 

Load filtering functions from static::$structure array.

Throws

\Gishiki\Core\MVC\Model\ActiveRecordException

workflow problem

executeFilters()

executeFilters(array  $data) : array

Apply data filters on the given data.

Parameters

array $data

the data to be filtered

Returns

array —

the filtered data, ready to be written to the database

executeFilter()

executeFilter(string  $key, mixed  $value) : mixed

Perform every necessary filtering value on a given model portion.

Parameters

string $key

the key associated with the given value

mixed $value

the value to be filtered

Returns

mixed —

the filtered value