abstract class StaticSchema extends Schema (View source)

Schema implementation that provides the schema definition via static class properties.

Properties

static protected string $model
static protected string $table
static protected string[]|string $primaryKey
static protected string[] $fields
static protected array[] $relationships

Methods

__construct(ContainerInterface $container)

Schema constructor.

from Schema
string
getModel()

Returns the model class used to operate on the records from this schema.

string
getTable()

Returns the name of the table for the schema.

array
getPrimaryKey()

Returns a list fields that define the primary key for the schema.

array
getFields()

Returns the list of fields for the schema.

array
getRelationshipDefinitions()

Returns an associative list of relationship definitions for the schema.

array
getRelationships()

Returns a list of all relationships for the schema.

from Schema
getRelationship(string $name)

Returns a single relationship with the given name.

from Schema
createRecord(Model $model = null)

Returns a new empty record for the schema.

from Schema
createRecordFromValues(array $values)

Returns a new record with the given values for the fields.

from Schema
createRecordFromRow(array $row, string $prefix = '')

Returns a new record with values taken from a result row with optional prefix for fields.

from Schema
createModel(Record $record)

Returns a new model that is associated to the given record.

from Schema
createModelFromRow(array $row, string $prefix = '', array $relationships = [])

Returns a new model with a new record that has values from the given result row with optional relationships.

from Schema

Details

__construct(ContainerInterface $container)

Schema constructor.

Parameters

ContainerInterface $container Container used to load schemas for relationships

string getModel()

Returns the model class used to operate on the records from this schema.

Return Value

string The model class used to operate on the records from this schema

string getTable()

Returns the name of the table for the schema.

Return Value

string Name of the table for the schema

array getPrimaryKey()

Returns a list fields that define the primary key for the schema.

Return Value

array List fields that define the primary key for the schema

array getFields()

Returns the list of fields for the schema.

Return Value

array List of fields for the schema

array getRelationshipDefinitions()

Returns an associative list of relationship definitions for the schema.

The returned array is an associative array of definitions, where each key defines the name of the relationship.

Each definition must contain the following fields: - key : Defines the field (or list of fields) in the schema that references fields in the referenced schema - schema : Name of the schema in the container that the the relationship references - field : Defines the field (or list of fields) in the referenced schema - unique : If relationship can ever only refer to a single record (optional)

If the unique value is missing or even if it's defined as false, the relationship will still be considered unique if the referenced fields contain the entire primary key of the referenced schema (as it is not possible to have multiple records with the same primary key).

Note that each relationship must have an appropriate reverse relationship defined in the referenced schema.

Return Value

array Associative list of relationship definitions for the schema

array getRelationships()

Returns a list of all relationships for the schema.

Return Value

array List of all relationships for the schema

Relationship getRelationship(string $name)

Returns a single relationship with the given name.

Parameters

string $name Name of the relationship

Return Value

Relationship Relationship with the given name

Exceptions

InvalidRelationshipException If a relationship with the given name does not exist

Record createRecord(Model $model = null)

Returns a new empty record for the schema.

Parameters

Model $model A model to associate to the record, if initialized

Return Value

Record A new empty record based on this schema

Record createRecordFromValues(array $values)

Returns a new record with the given values for the fields.

Parameters

array $values Values for the record fields

Return Value

Record New record with given values

Record createRecordFromRow(array $row, string $prefix = '')

Returns a new record with values taken from a result row with optional prefix for fields.

Parameters

array $row The result row from a database query
string $prefix Prefix for the fields used by this schema

Return Value

Record New record based on the fields taken from the result row

Model createModel(Record $record)

Returns a new model that is associated to the given record.

Parameters

Record $record The record associated to the model

Return Value

Model New model based on the given record

Model createModelFromRow(array $row, string $prefix = '', array $relationships = [])

Returns a new model with a new record that has values from the given result row with optional relationships.

Parameters

array $row Result row from the database
string $prefix Prefix for the fields of this schema
array $relationships Names of unique relationships also provided in the result row

Return Value

Model New model based on the values provided in the result row