PHP Класс izzum\statemachine\Transition

It has functionality to accept a Rule (guard logic) and a Command (transition logic) as well as callables for the guard logic and transition logic . callables are: closures, anonymous functions, user defined functions, instance methods, static methods etc. see the php manual. The guards are used to check whether a transition can take place (Rule and callable) The logic parts are used to execute the transition logic (Command and callable) Rules and commands should be able to be found/autoloaded by the application If transitions share the same states (both to and from) then they should point to the same object reference (same states should share the exact same state configuration).
Автор: Rolf Vreijdenberger
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$callable_guard callable the callable to call as part of the transition guard (should return a boolean)
$callable_transition callable the callable to call as part of the transition logic
$command string This can actually be a ',' seperated string of multiple commands.
$description string a description for the state
$event string an event code that can trigger this transitions
$rule string This can actually be a ',' seperated string of multiple rules.
$state_from State the state this transition starts from
$state_to State the state this transition points to

Открытые методы

Метод Описание
__construct ( State $state_from, State $state_to, string $event = null, string $rule = self::RULE_EMPTY, string $command = self::COMMAND_EMPTY, callable $callable_guard = self::CALLABLE_NULL, callable $callable_transition = self::CALLABLE_NULL )
__toString ( ) : string
can ( Context $context ) : boolean is a transition possible? Check the guard Rule with the domain object injected.
getCommand ( Context $context ) : izzum\command\ICommand returns the associated Command for this Transition.
getCommandName ( ) : string return the command name(s).
getCopy ( State $from, State $to ) : Transition for transitions that contain regex states, we need to be able to copy an existing (subclass of this) transition with all it's fields.
getDescription ( ) : string get the description for this transition (if any)
getEvent ( ) : string get the event name by which this transition can be triggered
getGuardCallable ( ) : callable returns the callable for the guard logic.
getName ( ) : string get the transition name.
getRule ( Context $context ) : izzum\rules\IRule returns the associated Rule for this Transition, configured with a 'reference' (stateful) object
getRuleName ( )
getStateFrom ( ) : State get the state this transition points from
getStateTo ( ) : State get the state this transition points to
getTransitionCallable ( ) : callable returns the callable for the transition logic.
isTriggeredBy ( string $event ) : boolean Can this transition be triggered by a certain event? This also matches on the transition name.
process ( Context $context ) : void Process the transition for the statemachine and execute the associated Command with the domain object injected.
setCommandName ( $command )
setDescription ( string $description ) set the description of the transition (for uml generation for example)
setEvent ( string $event ) set the event name by which this transition can be triggered.
setGuardCallable ( callable $callable ) the callable to call as part of the transition guard
setRuleName ( $rule )
setTransitionCallable ( callable $callable ) the callable to call as part of the transition logic
toString ( ) : string

Защищенные методы

Метод Описание
callCallable ( callable $callable, Context $context, $type = 'n/a' ) calls the $callable as part of the transition

Описание методов

__construct() публичный Метод

public __construct ( State $state_from, State $state_to, string $event = null, string $rule = self::RULE_EMPTY, string $command = self::COMMAND_EMPTY, callable $callable_guard = self::CALLABLE_NULL, callable $callable_transition = self::CALLABLE_NULL )
$state_from State
$state_to State
$event string optional: an event name by which this transition can be triggered
$rule string optional: one or more fully qualified Rule (sub)class name(s) to check to see if we are allowed to transition. This can actually be a ',' seperated string of multiple rules that will be applied as a chained 'and' rule.
$command string optional: one or more fully qualified Command (sub)class name(s) to execute for a transition. This can actually be a ',' seperated string of multiple commands that will be executed as a composite.
$callable_guard callable optional: a php callable to call. eg: "function(){echo 'closure called';};"
$callable_transition callable optional: a php callable to call. eg: "izzum\MyClass::myStaticMethod"

__toString() публичный Метод

public __toString ( ) : string
Результат string

callCallable() защищенный Метод

calls the $callable as part of the transition
protected callCallable ( callable $callable, Context $context, $type = 'n/a' )
$callable callable
$context Context

can() публичный Метод

is a transition possible? Check the guard Rule with the domain object injected.
public can ( Context $context ) : boolean
$context Context
Результат boolean

getCommand() публичный Метод

the Command will be configured with the 'reference' of the stateful object. In case there have been multiple commands as input (',' seperated), this method will return a Composite command.
public getCommand ( Context $context ) : izzum\command\ICommand
$context Context
Результат izzum\command\ICommand

getCommandName() публичный Метод

one or more fully qualified command (sub)class name(s) to execute for a transition. This can actually be a ',' seperated string of multiple commands that will be executed as a composite.
public getCommandName ( ) : string
Результат string

getCopy() публичный Метод

We need to instantiate it with a different from and to state since either one of those states can be the regex states. All other fields need to be copied. Override this method in a subclass to add other fields. By using 'new static' we are already instantiating a possible subclass.
public getCopy ( State $from, State $to ) : Transition
$from State
$to State
Результат Transition

getDescription() публичный Метод

get the description for this transition (if any)
public getDescription ( ) : string
Результат string

getEvent() публичный Метод

get the event name by which this transition can be triggered
public getEvent ( ) : string
Результат string

getGuardCallable() публичный Метод

returns the callable for the guard logic.
public getGuardCallable ( ) : callable
Результат callable or null

getName() публичный Метод

the transition name is always unique for a statemachine since it constists of _to_
public getName ( ) : string
Результат string

getRule() публичный Метод

returns the associated Rule for this Transition, configured with a 'reference' (stateful) object
public getRule ( Context $context ) : izzum\rules\IRule
$context Context the associated Context for a our statemachine
Результат izzum\rules\IRule a Rule or chained AndRule if the rule input was a ',' seperated string of rules.

getRuleName() публичный Метод

public getRuleName ( )

getStateFrom() публичный Метод

get the state this transition points from
public getStateFrom ( ) : State
Результат State

getStateTo() публичный Метод

get the state this transition points to
public getStateTo ( ) : State
Результат State

getTransitionCallable() публичный Метод

returns the callable for the transition logic.
public getTransitionCallable ( ) : callable
Результат callable or null

isTriggeredBy() публичный Метод

Can this transition be triggered by a certain event? This also matches on the transition name.
public isTriggeredBy ( string $event ) : boolean
$event string
Результат boolean

process() публичный Метод

Process the transition for the statemachine and execute the associated Command with the domain object injected.
public process ( Context $context ) : void
$context Context
Результат void

setCommandName() публичный Метод

public setCommandName ( $command )

setDescription() публичный Метод

set the description of the transition (for uml generation for example)
public setDescription ( string $description )
$description string

setEvent() публичный Метод

In case the event name is null or an empty string, it defaults to the transition name.
public setEvent ( string $event )
$event string

setGuardCallable() публичный Метод

the callable to call as part of the transition guard
public setGuardCallable ( callable $callable )
$callable callable

setRuleName() публичный Метод

public setRuleName ( $rule )

setTransitionCallable() публичный Метод

the callable to call as part of the transition logic
public setTransitionCallable ( callable $callable )
$callable callable

toString() публичный Метод

public toString ( ) : string
Результат string

Описание свойств

$callable_guard защищенное свойство

the callable to call as part of the transition guard (should return a boolean)
protected callable $callable_guard
Результат callable

$callable_transition защищенное свойство

the callable to call as part of the transition logic
protected callable $callable_transition
Результат callable

$command защищенное свойство

This can actually be a ',' seperated string of multiple commands.
protected string $command
Результат string

$description защищенное свойство

a description for the state
protected string $description
Результат string

$event защищенное свойство

an event code that can trigger this transitions
protected string $event
Результат string

$rule защищенное свойство

This can actually be a ',' seperated string of multiple rules.
protected string $rule
Результат string

$state_from защищенное свойство

the state this transition starts from
protected State,izzum\statemachine $state_from
Результат State

$state_to защищенное свойство

the state this transition points to
protected State,izzum\statemachine $state_to
Результат State