Source API for the «PorteModel» class

Model configuration for a given type of record.

Each type of record, stored as a table in a database, is associated to a table model and identified by a property "type". Model configuration is done at class level through the configuration of the record "config" property.

Public static methods

sanitize

Loop through a provided configuration array and normalize it. All keys defined in the configuration are optional. When defining the model configuration in the class definition, the provided configuration is stored in a "config" property.

The following keys are expected in the configuration:

  • database (string) Database name if multiple databases in the same connection, default to the connection database if defined
  • type (string) Key used to name the model
  • table (string) Table name as created in the database
  • class (string) Class name of the record, class must extend PorteRecord
  • engine (string) Table engine, default to "MYISAM" for "MySQL"
  • encoding (string) Table encoding, default to "utf8"
  • primary_key (string) Property used as the primary key, default to "id", property will be added to "properties" if not defined
  • properties (array) Associated array defined as "property=>configuration"

If not defined, the key "type" default to the singular the class name or the table name.
If not defined, the key "table" default to the pluralized type name.
If not defined, the key "class" default to the camelized "type" class if exists or the camelised and singular table class if exists or the "PorteRecord" class.

Note, if the "type" and "table" keys are not defined, the key "class" could not equals "PorteRecord".

sanitizeProperty

Sanatize a property of a model type.

return
mixed
True on success
$models
PorteModels, Models
instance where property is attached
$type
string, Type
of model for which property belongs
$property
string, Property
to sanitize
$config[optional]
array, If
provided, overwrite the property definition as provided in the "PorteModels->set" method
addMethod

This method is not yet documented.

deleteMethod

This method is not yet documented.

getFields

Return the column names as defined in the database table.

return
array
Column names
getSelects

Return an array of fields formated to be included in a query.

return
array
Array of string
getUniques

Extract unique indexes from the provided model.

return
mixed
Array for multi index as name=>[properties] or boolean for single index property=>true
Model
array, to
work with