PHP Класс LazyRecord\BaseModel

Наследование: implements Serializabl\Serializable, implements ArrayAcces\ArrayAccess, implements IteratorAggregat\IteratorAggregate, implements Countabl\Countable
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$_cacheInstance
$_currentUser Current user object
$alias
$autoReload Auto reload record after creating new record Turn off this if you want performance.
$currentUser Model-Scope current user object Book::$currentUser = new YourCurrentUser;
$dataLabelField
$dataValueField
$lastResult The last result object.
$mixin_classes Mixin classes are emtpy. (MixinDeclareSchema)
$selected
$usingDataSource static $schemaCache;
$yamlEncoding
$yamlExtension

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

Свойство Тип Описание
$_cache
$_cachePrefix
$_data
$_foreignRecordCache
$_preparedCreateStms
$_preparedFindSql
$_preparedFindStm prepared statement for find by primary key method.
$_preparedFindStms
$_schema

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

Метод Описание
__call ( $m, $a ) To support static operation methods like ::create, ::update, we can not define methods with the same name, so that we dispatch these methods from the magic method __call.
__clone ( )
__construct ( mixed $args = null, array $options = [] ) The constructor.
__get ( string $key ) Get record data, relational records, schema object or connection object.
__isset ( string $name ) Do we have this column ?
__set ( string $name, mixed $value ) Set column value.
afterCreate ( array $args ) Trigger for after creating new record.
afterDelete ( $args )
afterUpdate ( $args )
asCollection ( ) : LazyRecord\BaseCollection Return the collection object of current model object.
asCreateAction ( array $args = [], array $options = [] )
asDeleteAction ( array $args = [], array $options = [] )
asUpdateAction ( array $args = [], array $options = [] )
beforeCreate ( array $args ) : array Trigger method for "before creating new record".
beforeDelete ( $args ) Trigger method for.
beforeUpdate ( $args )
clear ( ) Clear current data stash.
clearInternalCache ( )
columns ( ) Get the RuntimeColumn objects from RuntimeSchema object.
count ( ) Countable interface
create ( array $args, array $options = [] ) : Result Method for creating new record, which is called from static::create and $record->create.
createOrUpdate ( array $args, array $byKeys = null ) Create or update an record by checking the existence from the $byKeys array that you defined.
currentUserCan ( CurrentUserInterface $user, string $right, array $args = [] ) Provide a basic access controll for model.
dataKeyValue ( ) This is for select widget, returns data key from specific column.
dataLabel ( ) This is for select widget, returns label value from specific column.
dataValue ( ) Alias method of $this->dataValue().
dbPrepareAndExecute ( PDO $conn, $sql, array $args = [] ) : PDOStatement We should move this method into connection manager.
dbQuery ( $dsId, string $sql ) : PDOStatement get pdo connetion and make a query.
deflate ( ) deflate current record data, usually deflate data from database turns data into objects, int, string (type casting).
deflateData ( array &$args ) : array deflate data from database.
delete ( ) : Result Delete current record, the record should be loaded already.
display ( string $name ) Render readable column value.
fastCreate ( array $args ) The fast create method does not reload record from created the primary key.
fetchManyToManyRelationCollection ( $relationId )
fetchOneToManyRelationCollection ( $relationId )
find ( $pkId ) Find record.
findMixinMethodClass ( string $m ) : string Find methods in mixin schema classes, methods will be called statically.
flushCache ( ) flush internal cache, in php memory.
free ( )
fromArray ( array $array ) Create from array.
get ( $key ) Get inflate value.
getAlias ( )
getCacheInstance ( )
getCachePrefix ( )
getConnection ( string $dsId = 'default' ) : PDO get default connection object (PDO) from connection manager.
getCurrentUser ( )
getData ( ) : array get current record data stash.
getDataLabelField ( )
getDataValueField ( )
getDeclareSchema ( )
getInternalCache ( string $key ) : mixed get internal cache from php memory.
getIterator ( ) =====================================
getLastResult ( )
getQueryDriver ( string $dsId ) Get SQL Query Driver by data source id.
getReadConnection ( ) : PDO Get PDO connection for reading data.
getReadQueryDriver ( ) : SQLBuilder\QueryDriver Get SQL Query driver object for reading data.
getReadSourceId ( )
getRecordActionClass ( $type )
getRelationalRecords ( $key, $relation = null )
getSchema ( )
getSchemaProxyClass ( )
getSelected ( )
getStashedData ( )
getTable ( )
getValue ( string $name ) : mixed Get the raw value from record (without deflator).
getWriteConnection ( ) : PDO Get PDO connection for writing data.
getWriteQueryDriver ( ) Get SQL Query driver object for writing data.
getWriteSourceId ( )
hasInternalCache ( $key )
hasValue ( string $name ) : boolean Check if the value exist.
inflateColumnValue ( string $n ) : mixed Inflate column value.
invokeAllMixinMethods ( string $m, array $a ) Invoke method on all mixin classes statically. this method does not return anything.
invokeMixinClassMethod ( string $mixinClass, string $m, array $a ) : mixed Invoke single mixin class method statically,.
load ( $args, array $options = null )
loadFromCache ( $args, $ttl = 3600 )
loadOrCreate ( array $args, array $byKeys = null ) Create a record if the record does not exists Otherwise the record should be updated with the arguments.
loadQuery ( string $sql, array $args = [], string $dsId = null ) : Result Load record from an sql query.
lockRead ( $alias = null )
lockWrite ( $alias = null )
newAction ( string $type, array $args = [], $options = [] ) Create an action from existing record object.
offsetExists ( $name )
offsetGet ( $name )
offsetSet ( $name, $value )
offsetUnset ( $name )
rawCreate ( array $args ) Simply create record without validation and triggers.
rawUpdate ( array $args ) Simply update record without validation and triggers.
reload ( string $pkId = null ) Relaod record data by primary key, parameter is optional if you've already defined the primary key column in this model.
reportError ( string $message, array $extra = [] ) : LazyRecord\Result\OperationError Report error.
reportSuccess ( string $message, array $extra = [] ) : Result Report success.
save ( ) : Result Save current data (create or update) if primary key is defined, do update if primary key is not defined, do create.
select ( $sels )
serialize ( ) ===============================
set ( $name, $value )
setAlias ( $alias )
setCurrentUser ( CurrentUserInterface $user )
setData ( array $array ) Set raw data.
setInternalCache ( string $key, mixed $val ) : mixed set internal cache, in php memory.
setPreferredTable ( $tableName )
setStashedData ( array $array )
toArray ( array $fields = null ) : array return data stash array,.
toInflatedArray ( ) : array Deflate data and return.
toJson ( ) : string return json format data.
toXml ( ) : string Return xml format data.
toYaml ( ) : string Return YAML format data.
unlock ( )
unserialize ( $data )
unsetPrimaryKey ( )
update ( array $args, $options = [] ) : Result Update current record.
using ( string $dsId ) Use specific data source for data operations.

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

Метод Описание
_validateColumn ( RuntimeColumn $column, $val, array $args ) Run validator to validate column.

Приватные методы

Метод Описание
getCache ( $key )
setCache ( $key, $val, $ttl )

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

__call() публичный метод

__call method is slower than normal method, because there are one more method table to look up. you should call create method if you need a better performance.
public __call ( $m, $a )

__clone() публичный метод

public __clone ( )

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

This constructor simply does nothing if no argument is passed. If the first argument is an integer, the record object will try to load the record by primary key with the given integer. If the first argument is an array, the record object will try to look up the record by treating the array as conditions, just like where([ ... ]) To avoid record object load the data, you can specify ['load' => false] as the option
public __construct ( mixed $args = null, array $options = [] )
$args mixed arguments for finding
$options array constructor options

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

Get record data, relational records, schema object or connection object.
public __get ( string $key )
$key string

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

Do we have this column ?
public __isset ( string $name )
$name string

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

Set column value.
public __set ( string $name, mixed $value )
$name string
$value mixed

_validateColumn() защищенный метод

A validator could be: 1. a ValidationKit validator, 2. a closure 3. a function name The validation result must be returned as in following format: boolean (valid or invalid, true or false) array( boolean valid , string message ) ValidationKit\ValidationMessage object. This method returns (object) { valid: boolean valid or invalid field: string field name message: }
protected _validateColumn ( RuntimeColumn $column, $val, array $args )
$column lazyrecord\schema\RuntimeColumn
$args array

afterCreate() публичный метод

Trigger for after creating new record.
public afterCreate ( array $args )
$args array

afterDelete() публичный метод

public afterDelete ( $args )

afterUpdate() публичный метод

public afterUpdate ( $args )

asCollection() публичный метод

Return the collection object of current model object.
public asCollection ( ) : LazyRecord\BaseCollection
Результат LazyRecord\BaseCollection

asCreateAction() публичный метод

public asCreateAction ( array $args = [], array $options = [] )
$args array
$options array

asDeleteAction() публичный метод

public asDeleteAction ( array $args = [], array $options = [] )
$args array
$options array

asUpdateAction() публичный метод

public asUpdateAction ( array $args = [], array $options = [] )
$args array
$options array

beforeCreate() публичный метод

By overriding this method, you can modify the arguments that is passed to the query builder. Remember to return the arguments back.
public beforeCreate ( array $args ) : array
$args array Arguments
Результат array $args Arguments

beforeDelete() публичный метод

Trigger method for.
public beforeDelete ( $args )

beforeUpdate() публичный метод

public beforeUpdate ( $args )

clear() публичный метод

Clear current data stash.
public clear ( )

clearInternalCache() публичный метод

public clearInternalCache ( )

columns() публичный метод

Get the RuntimeColumn objects from RuntimeSchema object.
public columns ( )

count() публичный метод

Countable interface
public count ( )

create() публичный метод

1. create method calls beforeCreate to trigger events or filter arguments. 2. it runs filterArrayWithColumns method to filter arguments with column definitions. 3. use currentUserCan method to check permission. 4. get column definitions and run filters, default value builders, canonicalizer, type constraint checkers to build a new arguments. 5. use these new arguments to build a SQL query with SQLBuilder\QueryBuilder. 6. insert SQL into data source (write) 7. reutrn the operation result.
public create ( array $args, array $options = [] ) : Result
$args array data
$options array
Результат Result operation result (success or error)

createOrUpdate() публичный метод

If the record exists, then the record should be updated. If the record does not exist, then the record should be created.
public createOrUpdate ( array $args, array $byKeys = null )
$args array
$byKeys array

currentUserCan() публичный метод

Provide a basic access controll for model.
public currentUserCan ( CurrentUserInterface $user, string $right, array $args = [] )
$user CurrentUserInterface Current user object, but be sure to implement CurrentUserInterface
$right string Can be 'create', 'update', 'load', 'delete'
$args array Arguments for operations (update, create, delete.. etc)

dataKeyValue() публичный метод

This is for select widget, returns data key from specific column.
public dataKeyValue ( )

dataLabel() публичный метод

This is for select widget, returns label value from specific column.
public dataLabel ( )

dataValue() публичный метод

Alias method of $this->dataValue().
public dataValue ( )

dbPrepareAndExecute() публичный метод

We should move this method into connection manager.
public dbPrepareAndExecute ( PDO $conn, $sql, array $args = [] ) : PDOStatement
$conn PDO
$args array
Результат PDOStatement

dbQuery() публичный метод

get pdo connetion and make a query.
public dbQuery ( $dsId, string $sql ) : PDOStatement
$sql string SQL statement
Результат PDOStatement pdo statement object. $stm = $this->dbQuery($sql); foreach( $stm as $row ) { $row['name']; }

deflate() публичный метод

deflate current record data, usually deflate data from database turns data into objects, int, string (type casting).
public deflate ( )

deflateData() публичный метод

for datetime object, deflate it into DateTime object. for integer object, deflate it into int type. for boolean object, deflate it into bool type.
public deflateData ( array &$args ) : array
$args array
Результат array current record data.

delete() публичный метод

Delete current record, the record should be loaded already.
public delete ( ) : Result
Результат Result operation result (success or error)

display() публичный метод

Render readable column value.
public display ( string $name )
$name string column name

fastCreate() публичный метод

TODO: refactor create code to call fastCreate. TODO: provide rawCreate to create data without validation.
public fastCreate ( array $args )
$args array

fetchManyToManyRelationCollection() публичный метод

public fetchManyToManyRelationCollection ( $relationId )

fetchOneToManyRelationCollection() публичный метод

public fetchOneToManyRelationCollection ( $relationId )

find() публичный метод

Find record.
public find ( $pkId )

findMixinMethodClass() публичный метод

Find methods in mixin schema classes, methods will be called statically.
public findMixinMethodClass ( string $m ) : string
$m string method name
Результат string the mixin class name.

flushCache() публичный метод

flush internal cache, in php memory.
public flushCache ( )

free() публичный метод

public free ( )

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

Create from array.
public static fromArray ( array $array )
$array array

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

Get inflate value.
public get ( $key )

getAlias() публичный метод

public getAlias ( )

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

public static getCacheInstance ( )

getCachePrefix() публичный метод

public getCachePrefix ( )

getConnection() публичный метод

get default connection object (PDO) from connection manager.
public getConnection ( string $dsId = 'default' ) : PDO
$dsId string data source id
Результат PDO

getCurrentUser() публичный метод

public getCurrentUser ( )

getData() публичный метод

DEPRECATED
public getData ( ) : array
Результат array record data stash

getDataLabelField() публичный метод

public getDataLabelField ( )

getDataValueField() публичный метод

public getDataValueField ( )

getDeclareSchema() публичный метод

public getDeclareSchema ( )

getInternalCache() публичный метод

get internal cache from php memory.
public getInternalCache ( string $key ) : mixed
$key string cache key
Результат mixed cached value

getIterator() публичный метод

=====================================
public getIterator ( )

getLastResult() публичный метод

public getLastResult ( )

getQueryDriver() публичный метод

Get SQL Query Driver by data source id.
public getQueryDriver ( string $dsId )
$dsId string Data source id.

getReadConnection() публичный метод

Get PDO connection for reading data.
public getReadConnection ( ) : PDO
Результат PDO

getReadQueryDriver() публичный метод

Get SQL Query driver object for reading data.
public getReadQueryDriver ( ) : SQLBuilder\QueryDriver
Результат SQLBuilder\QueryDriver

getReadSourceId() публичный метод

public getReadSourceId ( )

getRecordActionClass() публичный метод

public getRecordActionClass ( $type )

getRelationalRecords() публичный метод

public getRelationalRecords ( $key, $relation = null )

getSchema() публичный метод

public getSchema ( )

getSchemaProxyClass() публичный метод

public getSchemaProxyClass ( )

getSelected() публичный метод

public getSelected ( )

getStashedData() публичный метод

public getStashedData ( )

getTable() публичный метод

public getTable ( )

getValue() публичный метод

Get the raw value from record (without deflator).
public getValue ( string $name ) : mixed
$name string
Результат mixed

getWriteConnection() публичный метод

Get PDO connection for writing data.
public getWriteConnection ( ) : PDO
Результат PDO

getWriteQueryDriver() публичный метод

Get SQL Query driver object for writing data.
public getWriteQueryDriver ( )

getWriteSourceId() публичный метод

public getWriteSourceId ( )

hasInternalCache() публичный метод

public hasInternalCache ( $key )

hasValue() публичный метод

Check if the value exist.
public hasValue ( string $name ) : boolean
$name string
Результат boolean

inflateColumnValue() публичный метод

Inflate column value.
public inflateColumnValue ( string $n ) : mixed
$n string Column name
Результат mixed

invokeAllMixinMethods() публичный метод

Invoke method on all mixin classes statically. this method does not return anything.
public invokeAllMixinMethods ( string $m, array $a )
$m string method name.
$a array method arguments.

invokeMixinClassMethod() публичный метод

Invoke single mixin class method statically,.
public invokeMixinClassMethod ( string $mixinClass, string $m, array $a ) : mixed
$mixinClass string mixin class name.
$m string method name.
$a array
Результат mixed execution result

load() публичный метод

public load ( $args, array $options = null )
$options array

loadFromCache() публичный метод

public loadFromCache ( $args, $ttl = 3600 )

loadOrCreate() публичный метод

Create a record if the record does not exists Otherwise the record should be updated with the arguments.
public loadOrCreate ( array $args, array $byKeys = null )
$args array
$byKeys array it's optional if you defined primary key

loadQuery() публичный метод

Load record from an sql query.
public loadQuery ( string $sql, array $args = [], string $dsId = null ) : Result
$sql string sql statement
$args array
$dsId string data source id $result = $record->loadQuery( 'select * from ....', array( ... ) , 'master' );
Результат Result

lockRead() публичный метод

public lockRead ( $alias = null )

lockWrite() публичный метод

public lockWrite ( $alias = null )

newAction() публичный метод

Create an action from existing record object.
public newAction ( string $type, array $args = [], $options = [] )
$type string 'create','update','delete'
$args array

offsetExists() публичный метод

public offsetExists ( $name )

offsetGet() публичный метод

public offsetGet ( $name )

offsetSet() публичный метод

public offsetSet ( $name, $value )

offsetUnset() публичный метод

public offsetUnset ( $name )

rawCreate() публичный метод

Simply create record without validation and triggers.
public rawCreate ( array $args )
$args array

rawUpdate() публичный метод

Simply update record without validation and triggers.
public rawUpdate ( array $args )
$args array

reload() публичный метод

Relaod record data by primary key, parameter is optional if you've already defined the primary key column in this model.
public reload ( string $pkId = null )
$pkId string primary key name

reportError() публичный метод

Report error.
public reportError ( string $message, array $extra = [] ) : LazyRecord\Result\OperationError
$message string Error message.
$extra array Extra data.
Результат LazyRecord\Result\OperationError

reportSuccess() публичный метод

In this method, which pushs result object into ->results array. you can use flushResult() method to clean up these result objects.
public reportSuccess ( string $message, array $extra = [] ) : Result
$message string Success message.
$extra array Extra data.
Результат Result

save() публичный метод

Save current data (create or update) if primary key is defined, do update if primary key is not defined, do create.
public save ( ) : Result
Результат Result operation result (success or error)

select() публичный метод

public select ( $sels )

serialize() публичный метод

===============================
public serialize ( )

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

public set ( $name, $value )

setAlias() публичный метод

public setAlias ( $alias )

setCurrentUser() публичный метод

public setCurrentUser ( CurrentUserInterface $user )
$user CurrentUserInterface

setData() публичный метод

DEPRECATED
public setData ( array $array )
$array array

setInternalCache() публичный метод

set internal cache, in php memory.
public setInternalCache ( string $key, mixed $val ) : mixed
$key string cache key
$val mixed cache value
Результат mixed cached value

setPreferredTable() публичный метод

public setPreferredTable ( $tableName )

setStashedData() публичный метод

public setStashedData ( array $array )
$array array

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

return data stash array,.
public toArray ( array $fields = null ) : array
$fields array
Результат array

toInflatedArray() публичный метод

Deflate data and return.
public toInflatedArray ( ) : array
Результат array

toJson() публичный метод

return json format data.
public toJson ( ) : string
Результат string JSON string

toXml() публичный метод

Return xml format data.
public toXml ( ) : string
Результат string XML string

toYaml() публичный метод

Return YAML format data.
public toYaml ( ) : string
Результат string YAML string

unlock() публичный метод

public unlock ( )

unserialize() публичный метод

public unserialize ( $data )

unsetPrimaryKey() публичный метод

public unsetPrimaryKey ( )

update() публичный метод

Update current record.
public update ( array $args, $options = [] ) : Result
$args array
Результат Result operation result (success or error)

using() публичный метод

Use specific data source for data operations.
public using ( string $dsId )
$dsId string data source id.

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

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

protected $_cache

$_cacheInstance публичное статическое свойство

public static $_cacheInstance

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

protected $_cachePrefix

$_currentUser публичное свойство

Current user object
public $_currentUser

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

protected $_data

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

protected $_foreignRecordCache

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

protected $_preparedCreateStms

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

protected $_preparedFindSql

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

prepared statement for find by primary key method.
protected $_preparedFindStm

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

protected $_preparedFindStms

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

protected $_schema

$alias публичное свойство

public $alias

$autoReload публичное свойство

Auto reload record after creating new record Turn off this if you want performance.
public $autoReload

$currentUser публичное статическое свойство

Model-Scope current user object Book::$currentUser = new YourCurrentUser;
public static $currentUser

$dataLabelField публичное свойство

public $dataLabelField

$dataValueField публичное свойство

public $dataValueField

$lastResult публичное свойство

The last result object.
public $lastResult

$mixin_classes публичное статическое свойство

Mixin classes are emtpy. (MixinDeclareSchema)
public static $mixin_classes

$selected публичное свойство

public $selected

$usingDataSource публичное свойство

static $schemaCache;
public $usingDataSource

$yamlEncoding публичное статическое свойство

public static $yamlEncoding

$yamlExtension публичное статическое свойство

public static $yamlExtension