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).
파일 보기 프로젝트 열기: rolfvreijdenberger/izzum-statemachine 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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