izzum\statemachine\StateMachine::getCurrentState PHP Метод

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

the state will be: - the state that was explicitely set via setState - the state we have moved to after the last transition - the initial state. if we haven't had a transition yet and no current state has been set, the initial state will be retrieved (the state with State::TYPE_INITIAL)
public getCurrentState ( ) : State
Результат State
    public function getCurrentState()
    {
        // do we have a current state?
        if ($this->state) {
            return $this->state;
        }
        // retrieve state from the context if we do not find any state set.
        $state = $this->getState($this->getContext()->getState());
        if (!$state || $state == State::STATE_UNKNOWN) {
            // possible wrong configuration
            throw new Exception(sprintf("%s current state not found for state with name '%s'. %s", $this->toString(), $this->getContext()->getState(), 'are the transitions/states loaded and configured correctly?'), Exception::SM_NO_CURRENT_STATE_FOUND);
        }
        // state is found, set it and return
        $this->state = $state;
        return $this->state;
    }

Usage Example

$machine->addTransition(new Transition($drunk, $sleep, 'crash'));
$machine->addTransition(new Transition($drunk, $high, 'weedz'));
$machine->addTransition(new Transition($sleep, $hungry, 'wakeup'));
$machine->addTransition(new Transition($drunk, $dead, 'moreboozzz'));
$machine->addTransition(new Transition($smoking, $hungry, 'munchies'));
$machine->addTransition(new Transition($eating, $smoking, 'izzum'));
//http://www.urbandictionary.com/define.php?term=Izzum
$machine->addTransition(new Transition($smoking, $high, 'foshizzle'));
$machine->addTransition(new Transition($high, $dead, 'moreweedzzz'));
$machine->addTransition(new Transition($high, $sleep, 'pzzah'));
//start the interactive demo
//with some coloring that works in the bash shell
echo PHP_EOL . "Izzum statemachine interactive demo. press ctrl+c to stop it." . PHP_EOL . PHP_EOL;
//loop the machine
while (true) {
    $state = $machine->getCurrentState();
    echo "current state: {$state}" . PHP_EOL;
    echo "possible transitions from {$state}: " . PHP_EOL;
    if ($state->isFinal()) {
        //too much good times
        echo "Ahw man...! Try not to drink/smoke as much next time, it's bad for you ;)" . PHP_EOL . PHP_EOL;
        exit;
    }
    foreach ($state->getTransitions() as $transition) {
        echo "'" . $transition->getName() . "' aka event '" . $transition->getEvent() . "'" . PHP_EOL;
    }
    echo PHP_EOL;
    //get input from the user
    $event = readline("Enter an event or transition name: ");
    try {
        $status = 0;
All Usage Examples Of izzum\statemachine\StateMachine::getCurrentState