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
파일 보기 프로젝트 열기: rolfvreijdenberger/izzum-statemachine

공개 메소드들

메소드 설명
__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