PHP Class Spot\Entity

Afficher le fichier Open project: vlucas/spot2 Class Usage Examples

Protected Properties

Свойство Type Description
$_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

Méthodes publiques

Méthode Description
__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()

Méthodes protégées

Méthode Description
initFields ( ) Set all field values to their defaults or null

Method Details

__construct() public méthode

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

__destruct() public méthode

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

__get() public méthode

Getter for field properties
public __get ( string $field ) : boolean | mixed | null
$field string
Résultat boolean | mixed | null

__isset() public méthode

Enable isset() for object properties
public __isset ( string $key ) : boolean
$key string
Résultat boolean

__set() public méthode

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

__toString() public méthode

String representation of the class (JSON)
public __toString ( ) : string
Résultat string

data() public méthode

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() public méthode

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
Résultat array

dataModified() public méthode

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
Résultat array | boolean

dataUnmodified() public méthode

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
Résultat array | boolean

entity() public méthode

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() public méthode

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() public méthode

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
Résultat array | boolean | Entity Setter return self, getter returns array or boolean if key given and not found

events() public static méthode

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

fields() public static méthode

Return defined fields of the entity
public static fields ( ) : array
Résultat array

get() public méthode

public get ( string $field ) : boolean | mixed | null
$field string
Résultat boolean | mixed | null

hasErrors() public méthode

Check if any errors exist
public hasErrors ( string $field = null ) : boolean
$field string OPTIONAL field name
Résultat boolean

initFields() protected méthode

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

isModified() public méthode

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
Résultat boolean | null

isNew() public méthode

Is entity new (unsaved)?
public isNew ( null $new = null ) : boolean
$new null
Résultat boolean

jsonSerialize() public méthode

JsonSerializable
public jsonSerialize ( )

mapper() public static méthode

Mapper name getter
public static mapper ( ) : boolean
Résultat boolean

primaryKey() public méthode

Get the value of the primary key field defined on this entity
public primaryKey ( ) : mixed
Résultat mixed Value of the primary key field

primaryKeyField() public méthode

Get primary key field name
public primaryKeyField ( ) : string
Résultat string Primary key field name

relation() public méthode

Get/Set relation
public relation ( string $relationName, null $relationObj = null ) : boolean | mixed
$relationName string
$relationObj null
Résultat boolean | mixed

relations() public static méthode

Return defined fields of the entity
public static relations ( spot\MapperInterface $mapper, spot\EntityInterface $entity ) : array
$mapper spot\MapperInterface
$entity spot\EntityInterface
Résultat array

scopes() public static méthode

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 méthode

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

table() public static méthode

Table name getter/setter
public static table ( string | null $tableName = null ) : string
$tableName string | null
Résultat string

tableOptions() public static méthode

Datasource options getter/setter
public static tableOptions ( null | array $tableOpts = null ) : array
$tableOpts null | array
Résultat array

toArray() public méthode

Alias of self::data()
public toArray ( ) : array
Résultat array

Property Details

$_data protected_oe property

protected array $_data
Résultat array

$_dataModified protected_oe property

protected array $_dataModified
Résultat array

$_errors protected_oe property

Entity error messages (may be present after save attempt)
protected array $_errors
Résultat array

$_inGetter protected_oe property

protected array $_inGetter
Résultat array

$_inSetter protected_oe property

protected array $_inSetter
Résultat array

$_isNew protected_oe property

Entity state
protected bool $_isNew
Résultat boolean

$_objectId protected_oe property

protected string $_objectId
Résultat string

$mapper protected_oe static_oe property

protected static bool $mapper
Résultat boolean

$relationFields protected_oe static_oe property

Used internally so entity knows which fields are relations
protected static array $relationFields
Résultat array

$table protected_oe static_oe property

Table name
protected static string|null $table
Résultat string | null

$tableOptions protected_oe static_oe property

Datasource options
protected static array $tableOptions
Résultat array