PHP 클래스 izzum\statemachine\Context

A Context is created by your application to provide the right dependencies ('context') for the statemachine to work with. It seperates the concerns for the statemachine of how you are reading/writing state data and of how you access your domain models. Important are: - the entity id, which references an application domain specific object like 'Order' or 'Customer' that goes through some finite states in it's lifecycle. - the machine name, which is the type identifier for the machine and related to the entity (eg: 'order-machine') - persistence adapter, which reads/writes to/from a storage facility - entity_builder, which constructs the stateful entity. The entity is the object that will be acted upon by the Statemachine. This stateful object will be uniquely identified by it's id, which will mostly be some sort of primary key for that object that is defined by the application specific implementation. A reference to the stateful object can be obtained via the factory method getEntity(). This class delegates reading and writing states to specific implementations of the Adapter classes. this is useful for testing and creating specific behaviour for statemachines that need extra functionality to get and set the correct states.
저자: Rolf Vreijdenberger
파일 보기 프로젝트 열기: rolfvreijdenberger/izzum-statemachine 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$entity_builder EntityBuilder the builder to get the reference to the entity.
$identifier Identifier the Identifier that uniquely identifies the statemachine
$persistence_adapter izzum\statemachine\persistence\Adapter the instance for getting to the persistence layer
$statemachine StateMachine Only a statemachine that uses this Context should set itself on the Context, providing a bidirectional association.

공개 메소드들

메소드 설명
__construct ( Identifier $identifier, EntityBuilder $entity_builder = null, Adapter $persistence_adapter = null ) Constructor
__toString ( )
add ( string $state, string $message = null ) : boolean adds the state data to the persistence layer if it is not there.
getBuilder ( ) : EntityBuilder returns the builder used to get the application domain specific model.
getEntity ( boolean $create_fresh_entity = false ) : mixed Gets a (cached) reference to the application domain specific model, for example an 'Order' or 'Customer' that transitions through states in it's lifecycle.
getEntityId ( ) : string gets the entity id that represents the unique identifier for the application domain specific model.
getId ( boolean $readable = false, boolean $with_state = false ) : string get the unique identifier for an Context, which consists of the machine name and the entity_id in parseable form, with an optional state
getIdentifier ( ) : Identifier get the Identifier
getMachine ( ) : string gets the statemachine name that handles the entity
getPersistenceAdapter ( ) : Adapter gets the Context state reader/writer.
getState ( ) : string gets the state.
getStateMachine ( ) : StateMachine gets the associated statemachine (if a statemachine is associated)
setFailedTransition ( Transition $transition, Exception $e ) stores a failed transition, called by the statemachine This is a transition that has failed since it: - was not allowed - where an exception was thrown from a rule or command - etc. any general transition failure
setState ( string $state, string $message = null ) : boolan Sets the state
setStateMachine ( StateMachine $statemachine ) Provides a bidirectional association with the statemachine.
toString ( ) : string get the toString representation

메소드 상세

__construct() 공개 메소드

Constructor
public __construct ( Identifier $identifier, EntityBuilder $entity_builder = null, Adapter $persistence_adapter = null )
$identifier Identifier the identifier for the statemachine
$entity_builder EntityBuilder optional: A specific builder class to create a reference to the entity we wish to manipulate/have access to.
$persistence_adapter izzum\statemachine\persistence\Adapter optional: A specific reader/writer class can be used to generate different 'read/write' behaviour

__toString() 공개 메소드

public __toString ( )

add() 공개 메소드

Used to mark the initial construction of a statemachine at a certain point in time. subsequent calls to 'add' will not have any effect if it has already been persisted.
public add ( string $state, string $message = null ) : boolean
$state string
$message string optional message. this can be used by the persistence adapter to be part of the transition history to provide extra information about the transition.
리턴 boolean true if it was added, false if it was already there

getBuilder() 공개 메소드

returns the builder used to get the application domain specific model.
public getBuilder ( ) : EntityBuilder
리턴 EntityBuilder

getEntity() 공개 메소드

Gets a (cached) reference to the application domain specific model, for example an 'Order' or 'Customer' that transitions through states in it's lifecycle.
public getEntity ( boolean $create_fresh_entity = false ) : mixed
$create_fresh_entity boolean optional
리턴 mixed

getEntityId() 공개 메소드

gets the entity id that represents the unique identifier for the application domain specific model.
public getEntityId ( ) : string
리턴 string

getId() 공개 메소드

get the unique identifier for an Context, which consists of the machine name and the entity_id in parseable form, with an optional state
public getId ( boolean $readable = false, boolean $with_state = false ) : string
$readable boolean human readable or not. defaults to false
$with_state boolean append current state. defaults to false
리턴 string

getIdentifier() 공개 메소드

get the Identifier
public getIdentifier ( ) : Identifier
리턴 Identifier

getMachine() 공개 메소드

gets the statemachine name that handles the entity
public getMachine ( ) : string
리턴 string

getPersistenceAdapter() 공개 메소드

gets the Context state reader/writer.
public getPersistenceAdapter ( ) : Adapter
리턴 izzum\statemachine\persistence\Adapter a concrete persistence adapter

getState() 공개 메소드

first try the backend storage facility. If not found, then try the configured statemachine itself for the initial state.
public getState ( ) : string
리턴 string

getStateMachine() 공개 메소드

gets the associated statemachine (if a statemachine is associated)
public getStateMachine ( ) : StateMachine
리턴 StateMachine

setFailedTransition() 공개 메소드

stores a failed transition, called by the statemachine This is a transition that has failed since it: - was not allowed - where an exception was thrown from a rule or command - etc. any general transition failure
public setFailedTransition ( Transition $transition, Exception $e )
$transition Transition
$e Exception

setState() 공개 메소드

Sets the state
public setState ( string $state, string $message = null ) : boolan
$state string
$message string optional message. this can be used by the persistence adapter to be part of the transition history to provide extra information about the transition.
리턴 boolan true if there was never any state persisted for this machine before (just added for the first time), false otherwise

setStateMachine() 공개 메소드

This method should be called only by the StateMachine itself.
public setStateMachine ( StateMachine $statemachine )
$statemachine StateMachine

toString() 공개 메소드

get the toString representation
public toString ( ) : string
리턴 string

프로퍼티 상세

$entity_builder 보호되어 있는 프로퍼티

the builder to get the reference to the entity.
protected EntityBuilder,izzum\statemachine $entity_builder
리턴 EntityBuilder

$identifier 보호되어 있는 프로퍼티

the Identifier that uniquely identifies the statemachine
protected Identifier,izzum\statemachine $identifier
리턴 Identifier

$persistence_adapter 보호되어 있는 프로퍼티

the instance for getting to the persistence layer
protected Adapter,izzum\statemachine\persistence $persistence_adapter
리턴 izzum\statemachine\persistence\Adapter

$statemachine 보호되어 있는 프로퍼티

Only a statemachine that uses this Context should set itself on the Context, providing a bidirectional association.
protected StateMachine,izzum\statemachine $statemachine
리턴 StateMachine