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

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

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