Fork me on Github

Interface Finite\StateMachine\ StateMachineInterface

The Finite State Machine base Interface

Methods

initialize()

Initialize the State Machine current state

mixed apply( string $transitionName)

Apply a transition

bool can( string| TransitionInterface $transition)

Returns if the transition is applicable

addState( string| StateInterface $state)

addTransition( string| TransitionInterface $transition, string| null $initialState = null, string| null $finalState = null)

TransitionInterface getTransition( string $name)

Returns a transition by its name

StateInterface getState( string $name)

array<string> getTransitions()

Returns an array containing all the transitions names

array<string> getStates()

Returns an array containing all the states names

setObject( StatefulInterface $object)

StatefulInterface getObject()

StateInterface getCurrentState()

Details

public initialize()

Initialize the State Machine current state

public mixed apply( string $transitionName)

Apply a transition

Parameters
string $transitionName
Return Value
mixed

public bool can( string| TransitionInterface $transition)

Returns if the transition is applicable

Parameters
string| TransitionInterface $transition
Return Value
bool

public addState( string| StateInterface $state)

Parameters
string| StateInterface $state

public addTransition( string| TransitionInterface $transition, string| null $initialState = null, string| null $finalState = null)

Parameters
string| TransitionInterface $transition
string| null $initialState
string| null $finalState
Exceptions
InvalidArgumentException

public TransitionInterface getTransition( string $name)

Returns a transition by its name

Parameters
string $name
Return Value
TransitionInterface
Exceptions
TransitionException

public StateInterface getState( string $name)

Parameters
string $name
Return Value
StateInterface
Exceptions
TransitionException

public array<string> getTransitions()

Returns an array containing all the transitions names

Return Value
array<string>

public array<string> getStates()

Returns an array containing all the states names

Return Value
array<string>

public setObject( StatefulInterface $object)

Parameters
StatefulInterface $object

public StatefulInterface getObject()

Return Value
StatefulInterface

public StateInterface getCurrentState()

Return Value
StateInterface