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
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$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