PHP Class Bluz\Db\Row

Example of Users\Row namespace Application\Users; class Row extends \Bluz\Db\Row { public function beforeInsert() { $this->created = gmdate('Y-m-d H:i:s'); } public function beforeUpdate() { $this->updated = gmdate('Y-m-d H:i:s'); } } $userRow = new \Application\Users\Row(); $userRow -> login = 'username'; $userRow -> save();
Author: Anton Shevchuk
Inheritance: implements JsonSerializable, implements ArrayAccess, use trait Bluz\Common\Container\Container, use trait Bluz\Common\Container\ArrayAccess, use trait Bluz\Common\Container\JsonSerialize, use trait Bluz\Common\Container\MagicAccess
Mostrar archivo Open project: bluzphp/framework Class Usage Examples

Protected Properties

Property Type Description
$clean array This is set to a copy of $data when the data is fetched from a database, specified as a new tuple in the constructor, or when dirty data is posted to the database with save().
$relations relations rows
$table instance of Table class
$tableClass name of Table class

Public Methods

Method Description
__construct ( array $data = [] ) Create Row instance
__debugInfo ( ) : array Magic method for var_dump()
__sleep ( ) : string[] List of required for serialization properties
__toString ( ) : string Cast to string as class name
assert ( array | object $data ) : boolean Assert input data
delete ( ) : integer Delete existing row
getRelation ( string $modelName ) : Row | false Get relation by model name
getRelations ( string $modelName ) : array Get relations by model name
getTable ( ) : Table Returns the table object, or null if this is disconnected row
refresh ( ) : void Refreshes properties from the database
save ( ) : mixed Saves the properties to the database.
setRelation ( Row $row ) : Row Set relation
setTable ( Table $table ) : self Setup Table instance
validate ( array | object $data ) : boolean Validate input data

Protected Methods

Method Description
afterDelete ( ) : void Allows post-delete logic to be applied to row.
afterInsert ( ) : void Allows post-insert logic to be applied to row.
afterRead ( ) : void After read data from Db
afterSave ( ) : void Allows post-insert and post-update logic to be applied to row.
afterUpdate ( ) : void Allows post-update logic to be applied to row.
beforeDelete ( ) : void Allows pre-delete logic to be applied to row.
beforeInsert ( ) : void Allows pre-insert logic to be applied to row.
beforeSave ( ) : void Allows pre-insert and pre-update logic to be applied to row.
beforeUpdate ( ) : void Allows pre-update logic to be applied to row.
doInsert ( ) : mixed Insert row to Db
doUpdate ( ) : integer Update row
getPrimaryKey ( ) : array Retrieves an associative array of primary keys, if it exists

Method Details

__construct() public method

Create Row instance
public __construct ( array $data = [] )
$data array

__debugInfo() public method

Magic method for var_dump()
See also: var_dump()
public __debugInfo ( ) : array
return array

__sleep() public method

List of required for serialization properties
public __sleep ( ) : string[]
return string[]

__toString() public method

Cast to string as class name
public __toString ( ) : string
return string

afterDelete() protected method

Subclasses may override this method
protected afterDelete ( ) : void
return void

afterInsert() protected method

Subclasses may override this method
protected afterInsert ( ) : void
return void

afterRead() protected method

After read data from Db
protected afterRead ( ) : void
return void

afterSave() protected method

Subclasses may override this method
protected afterSave ( ) : void
return void

afterUpdate() protected method

Subclasses may override this method
protected afterUpdate ( ) : void
return void

assert() public method

Assert input data
public assert ( array | object $data ) : boolean
$data array | object
return boolean

beforeDelete() protected method

Subclasses may override this method
protected beforeDelete ( ) : void
return void

beforeInsert() protected method

Subclasses may override this method
protected beforeInsert ( ) : void
return void

beforeSave() protected method

Subclasses may override this method
protected beforeSave ( ) : void
return void

beforeUpdate() protected method

Subclasses may override this method
protected beforeUpdate ( ) : void
return void

delete() public method

Delete existing row
public delete ( ) : integer
return integer The number of deleted rows

doInsert() protected method

Insert row to Db
protected doInsert ( ) : mixed
return mixed The primary key value(s), as an associative array if the key is compound, or a scalar if the key is single-column

doUpdate() protected method

Update row
protected doUpdate ( ) : integer
return integer The number of rows updated

getPrimaryKey() protected method

Retrieves an associative array of primary keys, if it exists
protected getPrimaryKey ( ) : array
return array

getRelation() public method

Get relation by model name
public getRelation ( string $modelName ) : Row | false
$modelName string
return Row | false

getRelations() public method

Get relations by model name
public getRelations ( string $modelName ) : array
$modelName string
return array

getTable() public method

Returns the table object, or null if this is disconnected row
public getTable ( ) : Table
return Table

refresh() public method

Refreshes properties from the database
public refresh ( ) : void
return void

save() public method

This performs an intelligent insert/update, and reloads the properties with fresh data from the table on success.
public save ( ) : mixed
return mixed The primary key value(s), as an associative array if the key is compound, or a scalar if the key is single-column

setRelation() public method

Set relation
public setRelation ( Row $row ) : Row
$row Row
return Row

setTable() public method

Setup Table instance
public setTable ( Table $table ) : self
$table Table
return self

validate() public method

Validate input data
public validate ( array | object $data ) : boolean
$data array | object
return boolean

Property Details

$clean protected_oe property

This is set to a copy of $data when the data is fetched from a database, specified as a new tuple in the constructor, or when dirty data is posted to the database with save().
protected array $clean
return array

$relations protected_oe property

relations rows
protected $relations

$table protected_oe property

instance of Table class
protected $table

$tableClass protected_oe property

name of Table class
protected $tableClass