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
Afficher le fichier Open project: rolfvreijdenberger/izzum-statemachine

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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 méthode

do some cleanup
public __destruct ( )

addHistory() public méthode

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

getBooleanForDriver() protected méthode

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

getConnection() public méthode

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

getEntityIds() public méthode

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

getErrorInfo() protected méthode

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

getLoaderData() public méthode

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

getPrefix() final public méthode

get the table prefix
final public getPrefix ( ) : string
Résultat string

getTimestampForDriver() protected méthode

hook method
protected getTimestampForDriver ( ) : number | string
Résultat number | string

getTransitions() public méthode

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

getType() public méthode

public getType ( ) : string
Résultat string the type of backend we connect to

insertState() protected méthode

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

isPersisted() public méthode

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

load() public méthode

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

processGetState() public méthode

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

setConnection() public méthode

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 méthode

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

setupConnection() protected méthode

protected setupConnection ( PDO $connection )
$connection PDO

updateState() protected méthode

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