class Record extends Entity (View source)

Class Record

Constants

DUMP_ALL_DATA

UPDATE_NULLS

LOAD_DEFAULT

Methods

__construct(string $table = null, mixed $keys = 'id', AbstractDataMapper $mapper = null)

Object constructor to set table and key fields. In most cases this will be overridden by child classes to explicitly set the table and key fields for a particular database table.

bind(mixed $src, boolean $replaceNulls = false)

Method to bind an associative array or object to the AbstractTable instance. This method only binds properties that are publicly accessible and optionally takes an array of properties to ignore when binding.

set(string $key, mixed $value = null)

Magic setter to set a table field.

from Entity
mixed
get(string $key, mixed $default = null)

Magic getter to get a table field.

from Entity
boolean
exists(string $field)

Method to check a field exists.

from Entity
void
__set(string $field, mixed $value = null)

Set value.

from Entity
boolean
__isset(string $name)

__isset

from Entity
mixed
__get(string $field)

Get value.

from Entity
void
__unset(string $name)

__unset

from Entity
getIterator(bool $all = false)

Get an iterator object.

from Entity
boolean
offsetExists(mixed $offset)

Is a property exists or not.

from Entity
mixed
offsetGet(mixed $offset)

Get a property.

from Entity
void
offsetSet(mixed $offset, mixed $value)

Set a value to property.

from Entity
void
offsetUnset(mixed $offset)

Unset a property.

from Entity
int
count()

Count this object.

from Entity
boolean
isNull()

Is this object empty?

from Entity
boolean
notNull()

Is this object has properties?

from Data
array
dump(bool $all = false)

Dump all data as array

from Entity
map(callable $callback)

Mapping all elements.

from Data
walk(callable $callback, mixed $userdata = null)

Apply a user supplied function to every member of this object.

from Data
void
__clone()

Clone this object.

from Data
getFields(bool $reset = false)

loadFields

addField(string $field, string $default = null)

addField

from Entity
addFields(array $fields)

Add a field to this entity.

from Entity
removeField(string $field)

Remove field from this entity.

from Entity
boolean
hasField(string $name)

Method to check a field exists or not.

from Entity
setAlias(string $name, string $alias)

Set column alias.

from Entity
string
resolveAlias(string $name)

Resolve alias.

from Entity
reset(bool $loadDefault = true)

Method to reset class properties to the defaults set in the class definition. It will ignore the primary key as well as any private class properties.

$this
save(mixed $src, boolean $updateNulls = false)

Method to provide a shortcut to binding, checking and storing a AbstractTable instance to the database table. The method will check a row in once the data has been stored and if an ordering filter is present will attempt to reorder the table rows based on the filter. The ordering filter is an instance property name. The rows that will be reordered are those whose value matches the AbstractTable instance for the property specified.

load(mixed $keys = null, boolean $reset = true)

Method to load a row from the database by primary key and bind the fields to the AbstractTable instance properties.

delete(mixed $conditions = null)

Method to delete a row from the database table by primary key value.

validate()

Method to perform sanity checks on the AbstractTable instance properties to ensure they are safe to store in the database. Child classes should override this method to make sure the data they are storing in the database is safe and as expected before storage.

store(boolean $updateNulls = false)

Method to store a row in the database from the AbstractTable instance properties.

create()

create

update(bool $updateNulls = false)

update

string
getTableName()

Get the table name.

setTableName(string $table)

Method to set property table

array|mixed
getKeyName(boolean $multiple = false)

Method to get the primary key field name for the table.

boolean
hasPrimaryKey()

Validate that the primary key has been set.

bool
valueExists(string $field, null $value = null)

Check a field value exists in database or not, to keep a field unique.

triggerEvent(string|Event $event, array $args = array())

triggerEvent

getDispatcher()

Method to get property Dispatcher

setDispatcher(DispatcherInterface $dispatcher)

Method to set property dispatcher

loadDefault(bool $replace = false)

loadDefault

getDataMapper()

Method to get property Mapper

setDataMapper(AbstractDataMapper $mapper)

Method to set property mapper

Details

at line line 118
__construct(string $table = null, mixed $keys = 'id', AbstractDataMapper $mapper = null)

Object constructor to set table and key fields. In most cases this will be overridden by child classes to explicitly set the table and key fields for a particular database table.

Parameters

string $table Name of the table to model.
mixed $keys Name of the primary key field in the table or array of field names that compose the primary key.
AbstractDataMapper $mapper The DataMapper Adapter to access database.

at line line 185
Data bind(mixed $src, boolean $replaceNulls = false)

Method to bind an associative array or object to the AbstractTable instance. This method only binds properties that are publicly accessible and optionally takes an array of properties to ignore when binding.

Parameters

mixed $src An associative array or object to bind to the AbstractTable instance.
boolean $replaceNulls Replace null or not.

Return Value

Data Return self to support chaining.

in Entity at line line 291
Data set(string $key, mixed $value = null)

Magic setter to set a table field.

Parameters

string $key The key name.
mixed $value The value to set.

Return Value

Data Return self to support chaining.

Exceptions

InvalidArgumentException

in Entity at line line 310
mixed get(string $key, mixed $default = null)

Magic getter to get a table field.

Parameters

string $key The key name.
mixed $default The default value if not exists.

Return Value

mixed The value we want ot get.

in Entity at line line 391
boolean exists(string $field)

Method to check a field exists.

Parameters

string $field The field name to check.

Return Value

boolean True if exists.

in Entity at line line 250
void __set(string $field, mixed $value = null)

Set value.

Parameters

string $field The field to set.
mixed $value The value to set.

Return Value

void

Exceptions

InvalidArgumentException

in Entity at line line 236
boolean __isset(string $name)

__isset

Parameters

string $name

Return Value

boolean

in Entity at line line 262
mixed __get(string $field)

Get value.

Parameters

string $field The field to get.

Return Value

mixed

in Entity at line line 275
void __unset(string $name)

__unset

Parameters

string $name

Return Value

void

Exceptions

InvalidArgumentException

in Entity at line line 185
Traversable getIterator(bool $all = false)

Get an iterator object.

Parameters

bool $all

Return Value

Traversable An instance of an object implementing Iterator or Traversable

in Entity at line line 329
boolean offsetExists(mixed $offset)

Is a property exists or not.

Parameters

mixed $offset Offset key.

Return Value

boolean

in Entity at line line 342
mixed offsetGet(mixed $offset)

Get a property.

Parameters

mixed $offset Offset key.

Return Value

mixed The value to return.

Exceptions

InvalidArgumentException

in Entity at line line 356
void offsetSet(mixed $offset, mixed $value)

Set a value to property.

Parameters

mixed $offset Offset key.
mixed $value The value to set.

Return Value

void

Exceptions

InvalidArgumentException

in Entity at line line 369
void offsetUnset(mixed $offset)

Unset a property.

Parameters

mixed $offset Offset key to unset.

Return Value

void

Exceptions

InvalidArgumentException

in Entity at line line 379
int count()

Count this object.

Return Value

int

in Entity at line line 401
boolean isNull()

Is this object empty?

Return Value

boolean

in Data at line line 281
boolean notNull()

Is this object has properties?

Return Value

boolean

in Entity at line line 421
array dump(bool $all = false)

Dump all data as array

Parameters

bool $all

Return Value

array

in Data at line line 305
Data map(callable $callback)

Mapping all elements.

Parameters

callable $callback Callback to handle every element.

Return Value

Data Support chaining.

in Data at line line 325
Data walk(callable $callback, mixed $userdata = null)

Apply a user supplied function to every member of this object.

Parameters

callable $callback Callback to handle every element.
mixed $userdata This will be passed as the third parameter to the callback.

Return Value

Data Support chaining.

in Data at line line 344
void __clone()

Clone this object.

Return Value

void

at line line 486
stdClass[] getFields(bool $reset = false)

loadFields

Parameters

bool $reset

Return Value

stdClass[]

in Entity at line line 90
Entity addField(string $field, string $default = null)

addField

Parameters

string $field
string $default

Return Value

Entity

in Entity at line line 137
Entity addFields(array $fields)

Add a field to this entity.

Parameters

array $fields Fields array.

Return Value

Entity Return self to support chaining.

in Entity at line line 154
Entity removeField(string $field)

Remove field from this entity.

Parameters

string $field Field name.

Return Value

Entity Return self to support chaining.

in Entity at line line 170
boolean hasField(string $name)

Method to check a field exists or not.

Parameters

string $name

Return Value

boolean

in Entity at line line 198
Entity setAlias(string $name, string $alias)

Set column alias.

Parameters

string $name
string $alias

Return Value

Entity

in Entity at line line 219
string resolveAlias(string $name)

Resolve alias.

Parameters

string $name

Return Value

string

at line line 680
Entity reset(bool $loadDefault = true)

Method to reset class properties to the defaults set in the class definition. It will ignore the primary key as well as any private class properties.

Parameters

bool $loadDefault

Return Value

Entity

at line line 162
$this save(mixed $src, boolean $updateNulls = false)

Method to provide a shortcut to binding, checking and storing a AbstractTable instance to the database table. The method will check a row in once the data has been stored and if an ordering filter is present will attempt to reorder the table rows based on the filter. The ordering filter is an instance property name. The rows that will be reordered are those whose value matches the AbstractTable instance for the property specified.

Parameters

mixed $src An associative array or object to bind to the AbstractTable instance.
boolean $updateNulls True to update fields even if they are null.

Return Value

$this Method allows chaining

at line line 248
Record load(mixed $keys = null, boolean $reset = true)

Method to load a row from the database by primary key and bind the fields to the AbstractTable instance properties.

Parameters

mixed $keys An optional primary key value to load the row by, or an array of fields to match. If not set the instance property value is used.
boolean $reset True to reset the default values before loading the new row.

Return Value

Record Method allows chaining

Exceptions

RuntimeException
UnexpectedValueException
InvalidArgumentException

at line line 310
Record delete(mixed $conditions = null)

Method to delete a row from the database table by primary key value.

Parameters

mixed $conditions An optional primary key value to delete. If not set the instance property value is used.

Return Value

Record Method allows chaining

Exceptions

UnexpectedValueException

at line line 350
Record validate()

Method to perform sanity checks on the AbstractTable instance properties to ensure they are safe to store in the database. Child classes should override this method to make sure the data they are storing in the database is safe and as expected before storage.

Return Value

Record Method allows chaining

Exceptions

RuntimeException

at line line 368
Record store(boolean $updateNulls = false)

Method to store a row in the database from the AbstractTable instance properties.

If a primary key value is set the row with that primary key value will be updated with the instance property values. If no primary key value is set a new row will be inserted into the database with the properties from the AbstractTable instance.

Parameters

boolean $updateNulls True to update fields even if they are null.

Return Value

Record Method allows chaining

at line line 404
Record create()

create

Return Value

Record

at line line 429
Record update(bool $updateNulls = false)

update

Parameters

bool $updateNulls

Return Value

Record

at line line 460
string getTableName()

Get the table name.

Return Value

string

at line line 472
Record setTableName(string $table)

Method to set property table

Parameters

string $table

Return Value

Record Return self to support chaining.

at line line 513
array|mixed getKeyName(boolean $multiple = false)

Method to get the primary key field name for the table.

Parameters

boolean $multiple True to return all primary keys (as an array) or false to return just the first one (as a string).

Return Value

array|mixed Array of primary key field names or string containing the first primary key field.

at line line 532
boolean hasPrimaryKey()

Validate that the primary key has been set.

Return Value

boolean True if the primary key(s) have been set.

at line line 565
bool valueExists(string $field, null $value = null)

Check a field value exists in database or not, to keep a field unique.

Parameters

string $field The field name to check.
null $value

Return Value

bool

at line line 608
Event triggerEvent(string|Event $event, array $args = array())

triggerEvent

Parameters

string|Event $event
array $args

Return Value

Event

at line line 638
DispatcherInterface getDispatcher()

Method to get property Dispatcher

Return Value

DispatcherInterface

at line line 662
Record setDispatcher(DispatcherInterface $dispatcher)

Method to set property dispatcher

Parameters

DispatcherInterface $dispatcher

Return Value

Record Return self to support chaining.

at line line 700
Record loadDefault(bool $replace = false)

loadDefault

Parameters

bool $replace

Return Value

Record

at line line 718
AbstractDataMapper getDataMapper()

Method to get property Mapper

Return Value

AbstractDataMapper

at line line 735
Record setDataMapper(AbstractDataMapper $mapper)

Method to set property mapper

Parameters

AbstractDataMapper $mapper

Return Value

Record Return self to support chaining.