PHP 클래스 LazyRecord\BaseModel

상속: implements Serializabl\Serializable, implements ArrayAcces\ArrayAccess, implements IteratorAggregat\IteratorAggregate, implements Countabl\Countable
파일 보기 프로젝트 열기: corneltek/lazyrecord 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$_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

보호된 프로퍼티들

프로퍼티 타입 설명
$_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