PHP Class 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
Inheritance: extends Adapter, implements izzum\statemachine\loader\Loader
ファイルを表示 Open project: rolfvreijdenberger/izzum-statemachine

Public Methods

Method Description
__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

Protected Methods

Method Description
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}

Method Details

__construct() public method

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() public method

do some cleanup
public __destruct ( )

addHistory() public method

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

getBooleanForDriver() protected method

not all drivers have the same boolean datatype. convert here.
protected getBooleanForDriver ( boolean $boolean ) : boolean | integer | string
$boolean boolean
return boolean | integer | string

getConnection() public method

The connection retrieved will be reused if one already exists.
public getConnection ( ) : PDO
return PDO

getEntityIds() public method

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

getErrorInfo() protected method

collects error information ready to be used as output.
protected getErrorInfo ( PDOStatement $statement ) : string
$statement PDOStatement
return string

getLoaderData() public method

This method is public for testing purposes
public getLoaderData ( string $machine ) : Transition[]
$machine string the machine name
return izzum\statemachine\Transition[]

getPrefix() final public method

get the table prefix
final public getPrefix ( ) : string
return string

getTimestampForDriver() protected method

hook method
protected getTimestampForDriver ( ) : number | string
return number | string

getTransitions() public method

This method is public for testing purposes
public getTransitions ( string $machine ) : [][]
$machine string
return [][]

getType() public method

public getType ( ) : string
return string the type of backend we connect to

insertState() protected method

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

isPersisted() public method

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

load() public method

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

processGetState() public method

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

setConnection() public method

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() final public method

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

setupConnection() protected method

protected setupConnection ( PDO $connection )
$connection PDO

updateState() protected method

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