Documentation

Encoded extends Record
in package

Encoded record class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)

license

http://www.popphp.org/license New BSD License

version
5.3.0

Table of Contents

$base64Fields  : array<string|int, mixed>
Base64-encoded fields
$cipherMethod  : string
Cipher method
$encryptedFields  : array<string|int, mixed>
Encrypted fields
$hashAlgorithm  : string
Hash algorithm
$hashFields  : array<string|int, mixed>
Password-hashed fields
$hashOptions  : array<string|int, mixed>
Hash options
$isNew  : bool
Is new record flag
$iv  : string
Encrypted field IV (base64-encoded)
$jsonFields  : array<string|int, mixed>
JSON-encoded fields
$key  : string
Encrypted field key
$phpFields  : array<string|int, mixed>
PHP-serialized fields
$prefix  : string
Table prefix
$primaryKeys  : array<string|int, mixed>
Primary keys
$relationships  : array<string|int, mixed>
Relationships
$rowGateway  : Row
Row gateway
$table  : string
Table name
$tableGateway  : Table
Table gateway
$with  : array<string|int, mixed>
With relationships
$withChildren  : string
With relationship children
$withOptions  : array<string|int, mixed>
With relationship options
__callStatic()  : mixed
Call static method for 'findWhere'
__construct()  : mixed
Constructor
__get()  : mixed
Magic method to return the value of $this->rowGateway[$name]
__isset()  : bool
Magic method to return the isset value of $this->rowGateway[$name]
__set()  : void
Magic method to set the property to the value of $this->rowGateway[$name]
__unset()  : void
Magic method to unset $this->rowGateway[$name]
addWith()  : AbstractRecord
Set with relationships
belongsTo()  : Record|BelongsTo
Belongs to relationship
count()  : int
Method to get count of fields in row gateway
countRows()  : int
Get the count of rows returned in the result
db()  : AbstractAdapter
Get DB adapter (alias)
decode()  : array<string|int, mixed>
Scrub the column values and decode them
decodeValue()  : mixed
Decode value
decrement()  : void
Decrement the record column and save
delete()  : void
Delete the record
encode()  : array<string|int, mixed>
Scrub the column values and encode them
encodeValue()  : string
Encode value
execute()  : mixed
Static method to execute a custom prepared SQL statement.
findAll()  : static|Collection
Find all static method
findBy()  : Collection|array<string|int, mixed>
Find by static method
findById()  : static|array<string|int, mixed>
Find by ID static method
findByOrCreate()  : static|Collection|array<string|int, mixed>
Find by or create static method
findLatest()  : static|array<string|int, mixed>
Find latest static method
findOne()  : static|array<string|int, mixed>
Find one static method
findOneOrCreate()  : static|array<string|int, mixed>
Find one or create static method
getAll()  : Collection
Get all method
getBy()  : Collection|array<string|int, mixed>
Get by method
getById()  : static|array<string|int, mixed>
Get by ID method
getDb()  : AbstractAdapter
Get DB adapter
getDirty()  : array<string|int, mixed>
Get row's dirty columns
getFullTable()  : string
Get the full table name (prefix + table)
getIterator()  : ArrayIterator
Method to iterate over the columns
getOne()  : static|array<string|int, mixed>
Get one method
getPrefix()  : string
Get the table prefix
getPrimaryKeys()  : array<string|int, mixed>
Get the primary keys
getPrimaryValues()  : array<string|int, mixed>
Get the primary values
getRelationship()  : mixed
Get relationship
getRelationships()  : array<string|int, mixed>
Get relationships
getRowGateway()  : Row
Get the row gateway
getRows()  : Collection
Get the rows
getSql()  : Sql
Get SQL builder
getTable()  : string
Get the table
getTableGateway()  : Table
Get the table gateway
getTableInfo()  : array<string|int, mixed>
Static method to get the total count of a set from the DB table
getTotal()  : int
Static method to get the total count of a set from the DB table
getWithRelationships()  : AbstractRecord
Get with relationships
getWiths()  : array<string|int, mixed>
Get with relationships
hasDb()  : bool
Check for a DB adapter
hasMany()  : Collection|HasMany
Has many relationship
hasOne()  : Record|HasOne
Has one relationship
hasOneOf()  : Record|HasOneOf
Has one of relationship
hasRelationship()  : bool
Has relationship
hasRelationships()  : bool
Get relationships
hasRows()  : bool
Determine if the result has rows
hasWith()  : bool
Determine if there is specific with relationship
hasWiths()  : bool
Determine if there are with relationships
increment()  : void
Increment the record column and save
isDirty()  : bool
Check if row is dirty
isEncodedColumn()  : bool
Determine if column is an encoded column
offsetExists()  : bool
ArrayAccess offsetExists
offsetGet()  : mixed
ArrayAccess offsetGet
offsetSet()  : void
ArrayAccess offsetSet
offsetUnset()  : void
ArrayAccess offsetUnset
processRow()  : mixed
Process a table row
processRows()  : array<string|int, mixed>
Process table rows
processWithRelationships()  : AbstractRecord
Process with relationships
query()  : mixed
Static method to execute a custom SQL query.
replicate()  : static
Replicate the record
resetDirty()  : void
Reset row's dirty columns
rows()  : Collection
Get the rows (alias method)
save()  : void
Save or update the record
setColumns()  : Encoded
Set all the table column values at once
setDb()  : void
Set DB adapter
setDefaultDb()  : void
Set DB adapter
setPrefix()  : AbstractRecord
Set the table prefix
setPrimaryKeys()  : AbstractRecord
Set the primary keys
setRelationship()  : AbstractRecord
Set relationship
setRows()  : AbstractRecord
Set all the table rows at once
setTable()  : AbstractRecord
Set the table
setTableFromClassName()  : mixed
Set the table from a class name
sql()  : Sql
Get SQL builder (alias)
table()  : string
Get table name
toArray()  : array<string|int, mixed>
Get column values as array
verify()  : bool
Verify value against hash
with()  : static
With a 1:many relationship (eager-loading)

Properties

$base64Fields

Base64-encoded fields

protected array<string|int, mixed> $base64Fields = []

$cipherMethod

Cipher method

protected string $cipherMethod = null

$encryptedFields

Encrypted fields

protected array<string|int, mixed> $encryptedFields = []

$hashAlgorithm

Hash algorithm

protected string $hashAlgorithm = PASSWORD_BCRYPT

$hashFields

Password-hashed fields

protected array<string|int, mixed> $hashFields = []

$hashOptions

Hash options

protected array<string|int, mixed> $hashOptions = ['cost' => 10]

$iv

Encrypted field IV (base64-encoded)

protected string $iv = null

$jsonFields

JSON-encoded fields

protected array<string|int, mixed> $jsonFields = []

$key

Encrypted field key

protected string $key = null

$phpFields

PHP-serialized fields

protected array<string|int, mixed> $phpFields = []

$primaryKeys

Primary keys

protected array<string|int, mixed> $primaryKeys = ['id']

$relationships

Relationships

protected array<string|int, mixed> $relationships = []

$with

With relationships

protected array<string|int, mixed> $with = []

$withChildren

With relationship children

protected string $withChildren = null

$withOptions

With relationship options

protected array<string|int, mixed> $withOptions = []

Methods

__callStatic()

Call static method for 'findWhere'

public static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed

$users = Users::findWhereUsername('testuser');

Parameters
$name : string
$arguments : array<string|int, mixed>
Return values
mixed

__construct()

Constructor

public __construct() : mixed

Instantiate the database record object

Optional parameters are an array of column values, db adapter, or a table name

Return values
mixed

__get()

Magic method to return the value of $this->rowGateway[$name]

public __get(string $name) : mixed
Parameters
$name : string
Return values
mixed

__isset()

Magic method to return the isset value of $this->rowGateway[$name]

public __isset(string $name) : bool
Parameters
$name : string
Return values
bool

__set()

Magic method to set the property to the value of $this->rowGateway[$name]

public __set(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed
Return values
void

__unset()

Magic method to unset $this->rowGateway[$name]

public __unset(string $name) : void
Parameters
$name : string
Return values
void

addWith()

Set with relationships

public addWith(string $name[, array<string|int, mixed> $options = null ]) : AbstractRecord
Parameters
$name : string
$options : array<string|int, mixed> = null
Return values
AbstractRecord

belongsTo()

Belongs to relationship

public belongsTo(string $foreignTable, string $foreignKey[, array<string|int, mixed> $options = null ][, bool $eager = false ]) : Record|BelongsTo
Parameters
$foreignTable : string
$foreignKey : string
$options : array<string|int, mixed> = null
$eager : bool = false
Return values
Record|BelongsTo

count()

Method to get count of fields in row gateway

public count() : int
Return values
int

countRows()

Get the count of rows returned in the result

public countRows() : int
Return values
int

decode()

Scrub the column values and decode them

public decode(array<string|int, mixed> $columns) : array<string|int, mixed>
Parameters
$columns : array<string|int, mixed>
Return values
array<string|int, mixed>

decodeValue()

Decode value

public decodeValue(string $key, string $value) : mixed
Parameters
$key : string
$value : string
Tags
throws
Exception
Return values
mixed

decrement()

Decrement the record column and save

public decrement(string $column[, int $amount = 1 ]) : void
Parameters
$column : string
$amount : int = 1
Return values
void

delete()

Delete the record

public delete([array<string|int, mixed> $columns = null ]) : void
Parameters
$columns : array<string|int, mixed> = null
Return values
void

encode()

Scrub the column values and encode them

public encode(array<string|int, mixed> $columns) : array<string|int, mixed>
Parameters
$columns : array<string|int, mixed>
Return values
array<string|int, mixed>

encodeValue()

Encode value

public encodeValue(string $key, mixed $value) : string
Parameters
$key : string
$value : mixed
Tags
throws
Exception
Return values
string

execute()

Static method to execute a custom prepared SQL statement.

public static execute(mixed $sql[, array<string|int, mixed> $params = [] ][, bool $asArray = false ]) : mixed
Parameters
$sql : mixed
$params : array<string|int, mixed> = []
$asArray : bool = false
Return values
mixed

findAll()

Find all static method

public static findAll([array<string|int, mixed> $options = null ][, bool $asArray = false ]) : static|Collection
Parameters
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
static|Collection

findBy()

Find by static method

public static findBy([array<string|int, mixed> $columns = null ][, array<string|int, mixed> $options = null ][, bool $asArray = false ]) : Collection|array<string|int, mixed>
Parameters
$columns : array<string|int, mixed> = null
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
Collection|array<string|int, mixed>

findById()

Find by ID static method

public static findById(mixed $id[, array<string|int, mixed> $options = null ][, bool $asArray = false ]) : static|array<string|int, mixed>
Parameters
$id : mixed
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
static|array<string|int, mixed>

findByOrCreate()

Find by or create static method

public static findByOrCreate([array<string|int, mixed> $columns = null ][, array<string|int, mixed> $options = null ][, bool $asArray = false ]) : static|Collection|array<string|int, mixed>
Parameters
$columns : array<string|int, mixed> = null
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
static|Collection|array<string|int, mixed>

findLatest()

Find latest static method

public static findLatest([string $by = null ][, array<string|int, mixed> $columns = null ][, array<string|int, mixed> $options = null ][, bool $asArray = false ]) : static|array<string|int, mixed>
Parameters
$by : string = null
$columns : array<string|int, mixed> = null
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
static|array<string|int, mixed>

findOne()

Find one static method

public static findOne([array<string|int, mixed> $columns = null ][, array<string|int, mixed> $options = null ][, bool $asArray = false ]) : static|array<string|int, mixed>
Parameters
$columns : array<string|int, mixed> = null
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
static|array<string|int, mixed>

findOneOrCreate()

Find one or create static method

public static findOneOrCreate([array<string|int, mixed> $columns = null ][, array<string|int, mixed> $options = null ][, bool $asArray = false ]) : static|array<string|int, mixed>
Parameters
$columns : array<string|int, mixed> = null
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
static|array<string|int, mixed>

getAll()

Get all method

public getAll([array<string|int, mixed> $options = null ][, bool $asArray = false ]) : Collection
Parameters
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
Collection

getBy()

Get by method

public getBy([array<string|int, mixed> $columns = null ][, array<string|int, mixed> $options = null ][, bool $asArray = false ]) : Collection|array<string|int, mixed>
Parameters
$columns : array<string|int, mixed> = null
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
Collection|array<string|int, mixed>

getById()

Get by ID method

public getById(mixed $id[, array<string|int, mixed> $options = null ][, bool $asArray = false ]) : static|array<string|int, mixed>
Parameters
$id : mixed
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
static|array<string|int, mixed>

getDirty()

Get row's dirty columns

public getDirty() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFullTable()

Get the full table name (prefix + table)

public getFullTable() : string
Return values
string

getIterator()

Method to iterate over the columns

public getIterator() : ArrayIterator
Return values
ArrayIterator

getOne()

Get one method

public getOne([array<string|int, mixed> $columns = null ][, array<string|int, mixed> $options = null ][, bool $asArray = false ]) : static|array<string|int, mixed>
Parameters
$columns : array<string|int, mixed> = null
$options : array<string|int, mixed> = null
$asArray : bool = false
Return values
static|array<string|int, mixed>

getPrefix()

Get the table prefix

public getPrefix() : string
Return values
string

getPrimaryKeys()

Get the primary keys

public getPrimaryKeys() : array<string|int, mixed>
Return values
array<string|int, mixed>

getPrimaryValues()

Get the primary values

public getPrimaryValues() : array<string|int, mixed>
Return values
array<string|int, mixed>

getRelationship()

Get relationship

public getRelationship(string $name) : mixed
Parameters
$name : string
Return values
mixed

getRelationships()

Get relationships

public getRelationships() : array<string|int, mixed>
Return values
array<string|int, mixed>

getSql()

Get SQL builder

public static getSql() : Sql
Return values
Sql

getTable()

Get the table

public getTable() : string
Return values
string

getTableInfo()

Static method to get the total count of a set from the DB table

public static getTableInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTotal()

Static method to get the total count of a set from the DB table

public static getTotal([array<string|int, mixed> $columns = null ][, array<string|int, mixed> $options = null ]) : int
Parameters
$columns : array<string|int, mixed> = null
$options : array<string|int, mixed> = null
Return values
int

getWiths()

Get with relationships

public getWiths() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasDb()

Check for a DB adapter

public static hasDb() : bool
Return values
bool

hasMany()

Has many relationship

public hasMany(string $foreignTable, string $foreignKey[, array<string|int, mixed> $options = null ][, bool $eager = false ]) : Collection|HasMany
Parameters
$foreignTable : string
$foreignKey : string
$options : array<string|int, mixed> = null
$eager : bool = false
Return values
Collection|HasMany

hasOne()

Has one relationship

public hasOne(string $foreignTable, string $foreignKey[, array<string|int, mixed> $options = null ][, bool $eager = false ]) : Record|HasOne
Parameters
$foreignTable : string
$foreignKey : string
$options : array<string|int, mixed> = null
$eager : bool = false
Return values
Record|HasOne

hasOneOf()

Has one of relationship

public hasOneOf(string $foreignTable, string $foreignKey[, array<string|int, mixed> $options = null ][, bool $eager = false ]) : Record|HasOneOf
Parameters
$foreignTable : string
$foreignKey : string
$options : array<string|int, mixed> = null
$eager : bool = false
Return values
Record|HasOneOf

hasRelationship()

Has relationship

public hasRelationship(string $name) : bool
Parameters
$name : string
Return values
bool

hasRelationships()

Get relationships

public hasRelationships() : bool
Return values
bool

hasRows()

Determine if the result has rows

public hasRows() : bool
Return values
bool

hasWith()

Determine if there is specific with relationship

public hasWith(string $name) : bool
Parameters
$name : string
Return values
bool

hasWiths()

Determine if there are with relationships

public hasWiths() : bool
Return values
bool

increment()

Increment the record column and save

public increment(string $column[, int $amount = 1 ]) : void
Parameters
$column : string
$amount : int = 1
Return values
void

isDirty()

Check if row is dirty

public isDirty() : bool
Return values
bool

isEncodedColumn()

Determine if column is an encoded column

public isEncodedColumn(string $key) : bool
Parameters
$key : string
Return values
bool

offsetExists()

ArrayAccess offsetExists

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed
Return values
bool

offsetGet()

ArrayAccess offsetGet

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed
Return values
mixed

offsetSet()

ArrayAccess offsetSet

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
$value : mixed
Return values
void

offsetUnset()

ArrayAccess offsetUnset

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed
Return values
void

processRow()

Process a table row

public processRow(array<string|int, mixed> $row[, bool $asArray = false ]) : mixed
Parameters
$row : array<string|int, mixed>
$asArray : bool = false
Return values
mixed

processRows()

Process table rows

public processRows(array<string|int, mixed> $rows[, bool $asArray = false ]) : array<string|int, mixed>
Parameters
$rows : array<string|int, mixed>
$asArray : bool = false
Return values
array<string|int, mixed>

processWithRelationships()

Process with relationships

public processWithRelationships(array<string|int, mixed> $rows) : AbstractRecord
Parameters
$rows : array<string|int, mixed>
Return values
AbstractRecord

query()

Static method to execute a custom SQL query.

public static query(mixed $sql[, bool $asArray = false ]) : mixed
Parameters
$sql : mixed
$asArray : bool = false
Return values
mixed

replicate()

Replicate the record

public replicate([array<string|int, mixed> $replace = [] ]) : static
Parameters
$replace : array<string|int, mixed> = []
Return values
static

resetDirty()

Reset row's dirty columns

public resetDirty() : void
Return values
void

save()

Save or update the record

public save([array<string|int, mixed> $columns = null ]) : void
Parameters
$columns : array<string|int, mixed> = null
Return values
void

setColumns()

Set all the table column values at once

public setColumns([mixed $columns = null ]) : Encoded
Parameters
$columns : mixed = null
Tags
throws
Exception
Return values
Encoded

setDb()

Set DB adapter

public static setDb(AbstractAdapter $db[, string $prefix = null ][, bool $isDefault = false ]) : void
Parameters
$db : AbstractAdapter
$prefix : string = null
$isDefault : bool = false
Return values
void

setRows()

Set all the table rows at once

public setRows([array<string|int, mixed> $rows = null ][, bool $asArray = false ]) : AbstractRecord
Parameters
$rows : array<string|int, mixed> = null
$asArray : bool = false
Return values
AbstractRecord

setTableFromClassName()

Set the table from a class name

public setTableFromClassName([string $class = null ]) : mixed
Parameters
$class : string = null
Return values
mixed

sql()

Get SQL builder (alias)

public static sql() : Sql
Return values
Sql

table()

Get table name

public static table() : string
Return values
string

toArray()

Get column values as array

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

verify()

Verify value against hash

public verify(string $key, string $value) : bool
Parameters
$key : string
$value : string
Return values
bool

with()

With a 1:many relationship (eager-loading)

public static with(mixed $name[, array<string|int, mixed> $options = null ]) : static
Parameters
$name : mixed
$options : array<string|int, mixed> = null
Return values
static

Search results