PHP Класс Spot\Entity

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_data array
$_dataModified array
$_errors array Entity error messages (may be present after save attempt)
$_inGetter array
$_inSetter array
$_isNew boolean Entity state
$_objectId string
$mapper boolean
$relationFields array Used internally so entity knows which fields are relations
$table string | null Table name
$tableOptions array Datasource options

Открытые методы

Метод Описание
__construct ( array $data = [] ) Constructor - allows setting of object properties with array on construct
__destruct ( ) Do some cleanup of stored relations so orphaned relations are not held in memory
__get ( string $field ) : boolean | mixed | null Getter for field properties
__isset ( string $key ) : boolean Enable isset() for object properties
__set ( string $field, mixed $value ) Setter for field properties
__toString ( ) : string String representation of the class (JSON)
data ( null | array $data = null, boolean $modified = true, boolean $loadRelations = true ) Gets and sets data on the current entity
dataExcept ( array $except ) : array Return array of field data with data from the field names listed removed
dataModified ( null | string $field = null ) : array | boolean Gets data that has been modified since object construct, optionally allowing for selecting a single field
dataUnmodified ( null | string $field = null ) : array | boolean Gets data that has not been modified since object construct, optionally allowing for selecting a single field
entity ( ) Helper function so entity can be accessed via relation in a more consistent manner with 'entity()' without any errors (i.e. relation will not error if it already has a loaded entity object - it just returns $this)
error ( string $field, mixed $msg ) Add an error to error messages array
errors ( string | array $msgs = null, boolean $overwrite = true ) : array | boolean | Entity Error message getter/setter
events ( EventEmitter $eventEmitter ) Add events to this entity
fields ( ) : array Return defined fields of the entity
get ( string $field ) : boolean | mixed | null
hasErrors ( string $field = null ) : boolean Check if any errors exist
isModified ( null | string $field = null ) : boolean | null Returns true if a field has been modified.
isNew ( null $new = null ) : boolean Is entity new (unsaved)?
jsonSerialize ( ) JsonSerializable
mapper ( ) : boolean Mapper name getter
primaryKey ( ) : mixed Get the value of the primary key field defined on this entity
primaryKeyField ( ) : string Get primary key field name
relation ( string $relationName, null $relationObj = null ) : boolean | mixed Get/Set relation
relations ( spot\MapperInterface $mapper, spot\EntityInterface $entity ) : array Return defined fields of the entity
scopes ( ) Return scopes defined by this entity. Scopes are called from the Spot\Query object as a sort of in-context dynamic query method
set ( string $field, mixed $value, boolean $modified = true )
table ( string | null $tableName = null ) : string Table name getter/setter
tableOptions ( null | array $tableOpts = null ) : array Datasource options getter/setter
toArray ( ) : array Alias of self::data()

Защищенные методы

Метод Описание
initFields ( ) Set all field values to their defaults or null

Описание методов

__construct() публичный Метод

Constructor - allows setting of object properties with array on construct
public __construct ( array $data = [] )
$data array

__destruct() публичный Метод

Do some cleanup of stored relations so orphaned relations are not held in memory
public __destruct ( )

__get() публичный Метод

Getter for field properties
public __get ( string $field ) : boolean | mixed | null
$field string
Результат boolean | mixed | null

__isset() публичный Метод

Enable isset() for object properties
public __isset ( string $key ) : boolean
$key string
Результат boolean

__set() публичный Метод

Setter for field properties
public __set ( string $field, mixed $value )
$field string
$value mixed

__toString() публичный Метод

String representation of the class (JSON)
public __toString ( ) : string
Результат string

data() публичный Метод

Gets and sets data on the current entity
public data ( null | array $data = null, boolean $modified = true, boolean $loadRelations = true )
$data null | array
$modified boolean
$loadRelations boolean Determine if you want to load entity relations

dataExcept() публичный Метод

Return array of field data with data from the field names listed removed
public dataExcept ( array $except ) : array
$except array List of field names to exclude in data list returned
Результат array

dataModified() публичный Метод

Gets data that has been modified since object construct, optionally allowing for selecting a single field
public dataModified ( null | string $field = null ) : array | boolean
$field null | string
Результат array | boolean

dataUnmodified() публичный Метод

Gets data that has not been modified since object construct, optionally allowing for selecting a single field
public dataUnmodified ( null | string $field = null ) : array | boolean
$field null | string
Результат array | boolean

entity() публичный Метод

Helper function so entity can be accessed via relation in a more consistent manner with 'entity()' without any errors (i.e. relation will not error if it already has a loaded entity object - it just returns $this)
public entity ( )

error() публичный Метод

Add an error to error messages array
public error ( string $field, mixed $msg )
$field string Field name that error message relates to
$msg mixed Error message text - String or array of messages

errors() публичный Метод

Error message getter/setter
public errors ( string | array $msgs = null, boolean $overwrite = true ) : array | boolean | Entity
$msgs string | array string|array String return errors with field key, array sets errors
$overwrite boolean
Результат array | boolean | Entity Setter return self, getter returns array or boolean if key given and not found

events() публичный статический Метод

Add events to this entity
public static events ( EventEmitter $eventEmitter )
$eventEmitter EventEmitter

fields() публичный статический Метод

Return defined fields of the entity
public static fields ( ) : array
Результат array

get() публичный Метод

public get ( string $field ) : boolean | mixed | null
$field string
Результат boolean | mixed | null

hasErrors() публичный Метод

Check if any errors exist
public hasErrors ( string $field = null ) : boolean
$field string OPTIONAL field name
Результат boolean

initFields() защищенный Метод

Set all field values to their defaults or null
protected initFields ( )

isModified() публичный Метод

If no field name is passed in, return whether any fields have been changed
public isModified ( null | string $field = null ) : boolean | null
$field null | string
Результат boolean | null

isNew() публичный Метод

Is entity new (unsaved)?
public isNew ( null $new = null ) : boolean
$new null
Результат boolean

jsonSerialize() публичный Метод

JsonSerializable
public jsonSerialize ( )

mapper() публичный статический Метод

Mapper name getter
public static mapper ( ) : boolean
Результат boolean

primaryKey() публичный Метод

Get the value of the primary key field defined on this entity
public primaryKey ( ) : mixed
Результат mixed Value of the primary key field

primaryKeyField() публичный Метод

Get primary key field name
public primaryKeyField ( ) : string
Результат string Primary key field name

relation() публичный Метод

Get/Set relation
public relation ( string $relationName, null $relationObj = null ) : boolean | mixed
$relationName string
$relationObj null
Результат boolean | mixed

relations() публичный статический Метод

Return defined fields of the entity
public static relations ( spot\MapperInterface $mapper, spot\EntityInterface $entity ) : array
$mapper spot\MapperInterface
$entity spot\EntityInterface
Результат array

scopes() публичный статический Метод

Return scopes defined by this entity. Scopes are called from the Spot\Query object as a sort of in-context dynamic query method
public static scopes ( )

set() публичный Метод

public set ( string $field, mixed $value, boolean $modified = true )
$field string
$value mixed
$modified boolean

table() публичный статический Метод

Table name getter/setter
public static table ( string | null $tableName = null ) : string
$tableName string | null
Результат string

tableOptions() публичный статический Метод

Datasource options getter/setter
public static tableOptions ( null | array $tableOpts = null ) : array
$tableOpts null | array
Результат array

toArray() публичный Метод

Alias of self::data()
public toArray ( ) : array
Результат array

Описание свойств

$_data защищенное свойство

protected array $_data
Результат array

$_dataModified защищенное свойство

protected array $_dataModified
Результат array

$_errors защищенное свойство

Entity error messages (may be present after save attempt)
protected array $_errors
Результат array

$_inGetter защищенное свойство

protected array $_inGetter
Результат array

$_inSetter защищенное свойство

protected array $_inSetter
Результат array

$_isNew защищенное свойство

Entity state
protected bool $_isNew
Результат boolean

$_objectId защищенное свойство

protected string $_objectId
Результат string

$mapper защищенное статическое свойство

protected static bool $mapper
Результат boolean

$relationFields защищенное статическое свойство

Used internally so entity knows which fields are relations
protected static array $relationFields
Результат array

$table защищенное статическое свойство

Table name
protected static string|null $table
Результат string | null

$tableOptions защищенное статическое свойство

Datasource options
protected static array $tableOptions
Результат array