PHP Класс izzum\statemachine\persistence\PDO

PDO use database drivers for different backend implementations (postgres, mysql, sqlite, MSSQL, oracle etc). By providing a DSN connection string, you can connect to different backends. This specific adapter uses the schema as defined in - /assets/sql/postgres.sql - /assets/sql/sqlite.sql - /assets/sql/mysql.sql but can be used on tables for a different database vendor as long as the table names, fields and constraints are the same. Optionally, a prefix can be set. This Adapter does double duty as a Loader since both use the same backend. You could use two seperate classes for this, but you can implement both in one class. You could use the ReaderWriterDelegator to seperate the reading of configuration and the persisting of state and transition data. If you need an adapter more specialized to your needs/framework/system you can easily write one yourself. More functionality related to a backend can be implemented on this class eg: - get the history of transitions from the history table - get the factories for machines from the machine table
Автор: Rolf Vreijdenberger
Наследование: extends Adapter, implements izzum\statemachine\loader\Loader
Показать файл Открыть проект

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

Метод Описание
__construct ( string $dsn, string $user = null, string $password = null, array $options = [] )
__destruct ( ) do some cleanup
addHistory ( Identifier $identifier, $state, $message = null, $is_exception = false ) {@inheritDoc}
getConnection ( ) : PDO get the connection to a database via the PDO adapter.
getEntityIds ( $machine, $state = null ) {@inheritDoc}
getLoaderData ( string $machine ) : Transition[] gets all data for transitions.
getPrefix ( ) : string get the table prefix
getTransitions ( string $machine ) : [][] get all the ordered transition and state information for a specific machine.
getType ( ) : string
isPersisted ( Identifier $identifier ) {@inheritDoc}
load ( StateMachine $statemachine ) {@inheritDoc} This is an implemented method from the Loader interface.
processGetState ( Identifier $identifier ) {@inheritDoc}
setConnection ( PDO $connection ) set the PDO connection explicitely, useful if you want to share the PDO instance when it is created outside this class.
setPrefix ( string $prefix ) set the table prefix to be used

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

Метод Описание
getBooleanForDriver ( boolean $boolean ) : boolean | integer | string hook method.
getErrorInfo ( PDOStatement $statement ) : string collects error information ready to be used as output.
getTimestampForDriver ( ) : number | string hook method
insertState ( Identifier $identifier, $state, $message = null ) {@inheritDoc}
setupConnection ( PDO $connection )
updateState ( Identifier $identifier, $state, $message = null ) {@inheritDoc}

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

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

public __construct ( string $dsn, string $user = null, string $password = null, array $options = [] )
$dsn string a PDO data source name example: 'pgsql:host=localhost;port=5432;dbname=izzum'
$user string optional, defaults to null
$password string optional, defaults to null
$options array optional, defaults to empty array.

__destruct() публичный Метод

do some cleanup
public __destruct ( )

addHistory() публичный Метод

{@inheritDoc}
public addHistory ( Identifier $identifier, $state, $message = null, $is_exception = false )
$identifier izzum\statemachine\Identifier

getBooleanForDriver() защищенный Метод

not all drivers have the same boolean datatype. convert here.
protected getBooleanForDriver ( boolean $boolean ) : boolean | integer | string
$boolean boolean
Результат boolean | integer | string

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

The connection retrieved will be reused if one already exists.
public getConnection ( ) : PDO
Результат PDO

getEntityIds() публичный Метод

{@inheritDoc}
public getEntityIds ( $machine, $state = null )

getErrorInfo() защищенный Метод

collects error information ready to be used as output.
protected getErrorInfo ( PDOStatement $statement ) : string
$statement PDOStatement
Результат string

getLoaderData() публичный Метод

This method is public for testing purposes
public getLoaderData ( string $machine ) : Transition[]
$machine string the machine name
Результат izzum\statemachine\Transition[]

getPrefix() закрытый публичный Метод

get the table prefix
final public getPrefix ( ) : string
Результат string

getTimestampForDriver() защищенный Метод

hook method
protected getTimestampForDriver ( ) : number | string
Результат number | string

getTransitions() публичный Метод

This method is public for testing purposes
public getTransitions ( string $machine ) : [][]
$machine string
Результат [][]

getType() публичный Метод

public getType ( ) : string
Результат string the type of backend we connect to

insertState() защищенный Метод

{@inheritDoc}
protected insertState ( Identifier $identifier, $state, $message = null )
$identifier izzum\statemachine\Identifier

isPersisted() публичный Метод

{@inheritDoc}
public isPersisted ( Identifier $identifier )
$identifier izzum\statemachine\Identifier

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

All other methods are actually implemented methods from the Adapter class.
public load ( StateMachine $statemachine )
$statemachine izzum\statemachine\StateMachine

processGetState() публичный Метод

{@inheritDoc}
public processGetState ( Identifier $identifier )
$identifier izzum\statemachine\Identifier

setConnection() публичный Метод

set the PDO connection explicitely, useful if you want to share the PDO instance when it is created outside this class.
public setConnection ( PDO $connection )
$connection PDO

setPrefix() закрытый публичный Метод

set the table prefix to be used
final public setPrefix ( string $prefix )
$prefix string

setupConnection() защищенный Метод

protected setupConnection ( PDO $connection )
$connection PDO

updateState() защищенный Метод

{@inheritDoc}
protected updateState ( Identifier $identifier, $state, $message = null )
$identifier izzum\statemachine\Identifier