PHP Class atk4\data\Persistence

Inheritance: use trait atk4\core\ContainerTrait, use trait atk4\core\FactoryTrait, use trait atk4\core\HookTrait, use trait atk4\core\AppScopeTrait, use trait atk4\core\NameTrait
Show file Open project: atk4/data

Public Methods

Method Description
_add ( )
_serializeLoadField ( Field $f, mixed $value ) : mixed Override this to fine-tune un-serialization for your persistence.
_serializeSaveField ( Field $f, mixed $value ) : mixed Override this to fine-tune serialization for your persistence.
_typecastLoadField ( Field $f, mixed $value ) : mixed This is the actual field typecasting, which you can override in your persistence to implement necessary typecasting.
_typecastSaveField ( Field $f, mixed $value ) : mixed This is the actual field typecasting, which you can override in your persistence to implement necessary typecasting.
add ( Model | string $m, array $defaults = [] ) : Model Associate model with the data driver.
atomic ( callable $f ) : mixed Atomic executes operations within one begin/end transaction. Not all persistences will support atomic operations, so by default we just don't do anything.
connect ( string $dsn, string $user = null, string $password = null, array $args = [] ) : Persistence Connects database.
serializeLoadField ( Field $f, mixed $value ) : mixed Provided with a value, will perform field un-serialization.
serializeSaveField ( Field $f, mixed $value ) : mixed Provided with a value, will perform field serialization.
typecastLoadField ( Field $f, mixed $value ) : mixed Cast specific field value from the way how it's stored inside persistence to a PHP format.
typecastLoadRow ( Model $m, array $row ) : array Will convert one row of data from Persistence-specific types to PHP native types.
typecastSaveField ( Field $f, mixed $value ) : mixed Prepare value of a specific field by converting it to persistence-friendly format.
typecastSaveRow ( Model $m, array $row ) : array Will convert one row of data from native PHP types into persistence types. This will also take care of the "actual" field keys. Example:.

Protected Methods

Method Description
initPersistence ( Model $m ) Extend this method to enhance model to work with your persistence. Here you can define additional methods or store additional data. This method is executed before model's init().

Method Details

_add() public method

public _add ( )

_serializeLoadField() public method

Override this to fine-tune un-serialization for your persistence.
public _serializeLoadField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

_serializeSaveField() public method

Override this to fine-tune serialization for your persistence.
public _serializeSaveField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

_typecastLoadField() public method

This is the actual field typecasting, which you can override in your persistence to implement necessary typecasting.
public _typecastLoadField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

_typecastSaveField() public method

This is the actual field typecasting, which you can override in your persistence to implement necessary typecasting.
public _typecastSaveField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

add() public method

Associate model with the data driver.
public add ( Model | string $m, array $defaults = [] ) : Model
$m Model | string Model which will use this persistence
$defaults array Properties
return Model

atomic() public method

Atomic executes operations within one begin/end transaction. Not all persistences will support atomic operations, so by default we just don't do anything.
public atomic ( callable $f ) : mixed
$f callable
return mixed

connect() public static method

Connects database.
public static connect ( string $dsn, string $user = null, string $password = null, array $args = [] ) : Persistence
$dsn string
$user string
$password string
$args array
return Persistence

initPersistence() protected method

Extend this method to enhance model to work with your persistence. Here you can define additional methods or store additional data. This method is executed before model's init().
protected initPersistence ( Model $m )
$m Model

serializeLoadField() public method

Can be used for the purposes of encryption or storing unsupported formats.
public serializeLoadField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

serializeSaveField() public method

Can be used for the purposes of encryption or storing unsupported formats.
public serializeSaveField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

typecastLoadField() public method

Cast specific field value from the way how it's stored inside persistence to a PHP format.
public typecastLoadField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

typecastLoadRow() public method

NOTE: Please DO NOT perform "actual" field mapping here, because data may be "aliased" from SQL persistences or mapped depending on persistence driver.
public typecastLoadRow ( Model $m, array $row ) : array
$m Model
$row array
return array

typecastSaveField() public method

Prepare value of a specific field by converting it to persistence-friendly format.
public typecastSaveField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

typecastSaveRow() public method

In: [ 'name'=>' John Smith', 'age'=>30, 'password'=>'abc', 'is_married'=>true, ] Out: [ 'first_name'=>'John Smith', 'age'=>30, 'is_married'=>1 ]
public typecastSaveRow ( Model $m, array $row ) : array
$m Model
$row array
return array