PHP 클래스 izzum\statemachine\State

A State instance can (and should) be shared by multiple Transition objects when it is the same State for their origin/from State. A State can be a regex state (or negated regex). A regex state can be used in a transition and when added to a statemachine the regular expression will be matched on all currently known states on that statemachine and new Transitions will be added to the statemachine that match the from/to state regexes. This is very useful to build a lot of transitions very quickly. to build a full mesh of transitions (all states to all states): $a = new State('a'); $b = new State('b'); $c = new State('c'); $machine->addState($a); $machine->addState($b); $machine->addState($c); $state_regex_all = new State('regex:|.*|'); $machine->addTransition(new Transition($state_regex_all, $state_regex_all));
파일 보기 프로젝트 열기: rolfvreijdenberger/izzum-statemachine 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$callable_entry callable the entry callable method
$callable_exit callable the exit callable method
$command_entry_name string This can actually be a ',' seperated string of multiple commands that will be executed as a composite.
$command_exit_name string This can actually be a ',' seperated string of multiple commands that will be executed as a composite.
$description string a description for the state
$name string The name of the state
$transitions Transition[] These will be set by Transition objects (they provide the association) this is not a hashmap, so the order of Transitions *might* be important. whenever a State is asked for it's transitions, the first transition might be tried first. this might have performance and configuration benefits
$type string The state type: - State::TYPE_INITIAL - State::TYPE_NORMAL - State::TYPE_FINAL - State::TYPE_REGEX

공개 메소드들

메소드 설명
__construct ( string $name, string $type = self::TYPE_NORMAL, $command_entry_name = self::COMMAND_EMPTY, $command_exit_name = self::COMMAND_EMPTY, callable $callable_entry = self::CALLABLE_NULL, callable $callable_exit = self::CALLABLE_NULL )
__toString ( ) : string
addTransition ( Transition $transition ) : boolan add an outgoing transition from this state.
entryAction ( Context $context ) An action executed every time a state is entered.
exitAction ( Context $context ) An action executed every time a state is exited.
getDescription ( ) : string get the description for this state (if any)
getEntryCallable ( ) : callable get the entry callable, the callable to be called when entering this state
getEntryCommandName ( ) : string get the fully qualified command name for entry of the state
getExitCallable ( ) : callable get the exit callable, the callable to be called when exiting this state
getExitCommandName ( ) : string get the fully qualified command name for exit of the state
getName ( ) gets the name of this state
getTransitions ( ) : Transition[] get all outgoing transitions
getTransitionsTriggeredByEvent ( string $event ) : Transition[] get the transition for this state that can be triggered by an event code.
getType ( ) : string get the state type
hasTransition ( string $transition_name ) : boolean Do we have a transition from this state with a certain name?
isFinal ( ) : boolean is it a final state
isInitial ( ) : boolean is it an initial state
isNegatedRegex ( ) : boolean is this state a negated regex type of state? "not-regex:"
isNormal ( ) : boolean is it a normal state
isNormalRegex ( ) : boolean is this state a normal regex type of state? "regex:"
isRegex ( ) : boolean is this state a regex type of state? formats: "regex:" "not-regex:"
setDescription ( string $description ) set the description of the state (for uml generation for example)
setEntryCallable ( callable $callable ) set the entry callable, the callable to be called when entering this state
setEntryCommandName ( string $name ) set the entry command name
setExitCallable ( callable $callable ) set the exit callable, the callable to be called when exiting this state
setExitCommandName ( string $name ) set the exit command name

보호된 메소드들

메소드 설명
callCallable ( callable $callable, Context $context, string $type = 'n/a' ) calls a $callable if it exists, with the arguments $context->getEntity()
execute ( izzum\command\ICommand $command ) helper method
getCommand ( string $command_name, Context $context ) : izzum\command\ICommand returns the associated Command for the entry/exit action.
setName ( string $name ) sets the name of this state
setType ( string $type ) set the state type

메소드 상세

__construct() 공개 메소드

public __construct ( string $name, string $type = self::TYPE_NORMAL, $command_entry_name = self::COMMAND_EMPTY, $command_exit_name = self::COMMAND_EMPTY, callable $callable_entry = self::CALLABLE_NULL, callable $callable_exit = self::CALLABLE_NULL )
$name string the name of the state (can also be a regex in format: [not-]regex://)
$type string the type of the state (on of self::TYPE_<*>)
$command_entry_name optional: a command to be executed when a transition enters this state One or more fully qualified command (sub)class name(s) to execute when entering this state. This can actually be a ',' seperated string of multiple commands that will be executed as a composite.
$command_exit_name optional: a command to be executed when a transition leaves this state One or more fully qualified command (sub)class name(s) to execute when exiting this state. This can actually be a ',' seperated string of multiple commands that will be executed as a composite.
$callable_entry callable optional: a php callable to call. eg: "function(){echo 'closure called';};"
$callable_exit callable optional: a php callable to call. eg: "izzum\MyClass::myStaticMethod"

__toString() 공개 메소드

public __toString ( ) : string
리턴 string

addTransition() 공개 메소드

TRICKY: this method should be package visibility only, so don't use directly. it is used to set the bidirectional association for State and Transition from a Transition instance on the state the transition will be allowed to run from ('state from').
public addTransition ( Transition $transition ) : boolan
$transition Transition
리턴 boolan yes in case the transition was not on the State already or in case of an invalid transition

callCallable() 보호된 메소드

calls a $callable if it exists, with the arguments $context->getEntity()
protected callCallable ( callable $callable, Context $context, string $type = 'n/a' )
$callable callable
$context Context
$type string the type of callable (self::CALLABLE_ENTRY | self::CALLABLE_EXIT)

entryAction() 공개 메소드

An entry action will not be executed for an 'initial' state.
public entryAction ( Context $context )
$context Context

execute() 보호된 메소드

helper method
protected execute ( izzum\command\ICommand $command )
$command izzum\command\ICommand

exitAction() 공개 메소드

An exit action will not be executed for a 'final' state since a machine will not leave a 'final' state.
public exitAction ( Context $context )
$context Context

getCommand() 보호된 메소드

the Command will be configured with the domain model via dependency injection
protected getCommand ( string $command_name, Context $context ) : izzum\command\ICommand
$command_name string entry or exit command name
$context Context
리턴 izzum\command\ICommand

getDescription() 공개 메소드

get the description for this state (if any)
public getDescription ( ) : string
리턴 string

getEntryCallable() 공개 메소드

get the entry callable, the callable to be called when entering this state
public getEntryCallable ( ) : callable
리턴 callable

getEntryCommandName() 공개 메소드

get the fully qualified command name for entry of the state
public getEntryCommandName ( ) : string
리턴 string

getExitCallable() 공개 메소드

get the exit callable, the callable to be called when exiting this state
public getExitCallable ( ) : callable
리턴 callable

getExitCommandName() 공개 메소드

get the fully qualified command name for exit of the state
public getExitCommandName ( ) : string
리턴 string

getName() 공개 메소드

gets the name of this state
public getName ( )

getTransitions() 공개 메소드

get all outgoing transitions
public getTransitions ( ) : Transition[]
리턴 Transition[] an array of transitions

getTransitionsTriggeredByEvent() 공개 메소드

get the transition for this state that can be triggered by an event code.
public getTransitionsTriggeredByEvent ( string $event ) : Transition[]
$event string the event code that can trigger a transition (mealy machine)
리턴 Transition[]

getType() 공개 메소드

get the state type
public getType ( ) : string
리턴 string

hasTransition() 공개 메소드

Do we have a transition from this state with a certain name?
public hasTransition ( string $transition_name ) : boolean
$transition_name string
리턴 boolean

isFinal() 공개 메소드

is it a final state
public isFinal ( ) : boolean
리턴 boolean

isInitial() 공개 메소드

is it an initial state
public isInitial ( ) : boolean
리턴 boolean

isNegatedRegex() 공개 메소드

is this state a negated regex type of state? "not-regex:"
public isNegatedRegex ( ) : boolean
리턴 boolean

isNormal() 공개 메소드

is it a normal state
public isNormal ( ) : boolean
리턴 boolean

isNormalRegex() 공개 메소드

is this state a normal regex type of state? "regex:"
public isNormalRegex ( ) : boolean
리턴 boolean

isRegex() 공개 메소드

is this state a regex type of state? formats: "regex:" "not-regex:"
public isRegex ( ) : boolean
리턴 boolean

setDescription() 공개 메소드

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

setEntryCallable() 공개 메소드

set the entry callable, the callable to be called when entering this state
public setEntryCallable ( callable $callable )
$callable callable

setEntryCommandName() 공개 메소드

set the entry command name
public setEntryCommandName ( string $name )
$name string a fully qualified command name

setExitCallable() 공개 메소드

set the exit callable, the callable to be called when exiting this state
public setExitCallable ( callable $callable )
$callable callable

setExitCommandName() 공개 메소드

set the exit command name
public setExitCommandName ( string $name )
$name string a fully qualified command name

setName() 보호된 메소드

sets the name of this state
protected setName ( string $name )
$name string

setType() 보호된 메소드

set the state type
protected setType ( string $type )
$type string

프로퍼티 상세

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

the entry callable method
protected callable $callable_entry
리턴 callable

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

the exit callable method
protected callable $callable_exit
리턴 callable

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

This can actually be a ',' seperated string of multiple commands that will be executed as a composite.
protected string $command_entry_name
리턴 string

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

This can actually be a ',' seperated string of multiple commands that will be executed as a composite.
protected string $command_exit_name
리턴 string

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

a description for the state
protected string $description
리턴 string

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

The name of the state
protected string $name
리턴 string

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

These will be set by Transition objects (they provide the association) this is not a hashmap, so the order of Transitions *might* be important. whenever a State is asked for it's transitions, the first transition might be tried first. this might have performance and configuration benefits
protected Transition[],izzum\statemachine $transitions
리턴 Transition[]

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

The state type: - State::TYPE_INITIAL - State::TYPE_NORMAL - State::TYPE_FINAL - State::TYPE_REGEX
protected string $type
리턴 string