/** * Invokes the action. * * @param Stagehand_FSM &$fsm * @throws STAGEHAND_FSM_ERROR_NOT_CALLABLE */ function invokeAction(&$fsm) { if (is_null($this->_action)) { return; } if (!is_callable($this->_action)) { Stagehand_FSM_Error::push(STAGEHAND_FSM_ERROR_NOT_CALLABLE, 'The action is not callable.'); return; } $payload =& $fsm->getPayload(); call_user_func_array($this->_action, array(&$fsm, &$this, &$payload)); }
/** * Processes an event. * * @param string $eventName * @param boolean $transitionToHistoryMarker * @return Stagehand_FSM_State * @throws STAGEHAND_FSM_ERROR_ALREADY_SHUTDOWN * @since Method available since Release 1.7.0 */ function &_processEvent($eventName, $transitionToHistoryMarker = false) { if ($this->_currentState->getName() == STAGEHAND_FSM_STATE_FINAL && !$this->_isSpecialEvent($eventName)) { Stagehand_FSM_Error::push(STAGEHAND_FSM_ERROR_ALREADY_SHUTDOWN, 'The FSM was already shutdown.'); $return = null; return $return; } $event =& $this->_currentState->getEvent($eventName); if (!is_null($event)) { if (!$this->_isSpecialEvent($eventName)) { $result = $event->evaluateGuard($this); if (Stagehand_FSM_Error::hasErrors()) { $return = null; return $return; } if (!$result) { $eventName = STAGEHAND_FSM_EVENT_DO; $event =& $this->_currentState->getEvent(STAGEHAND_FSM_EVENT_DO); } } } else { $eventName = STAGEHAND_FSM_EVENT_DO; $event =& $this->_currentState->getEvent(STAGEHAND_FSM_EVENT_DO); } if (!$this->_isSpecialEvent($eventName)) { $this->_processEvent(STAGEHAND_FSM_EVENT_EXIT, $transitionToHistoryMarker); if (Stagehand_FSM_Error::hasErrors()) { $return = null; return $return; } } if (!$this->_isSpecialEvent($eventName)) { $nextStateName = $event->getNextState(); $this->_transition($nextStateName); } $event->invokeAction($this); if (Stagehand_FSM_Error::hasErrors()) { $return = null; return $return; } if ($this->_isEntryEvent($eventName) && is_a($this->_currentState, __CLASS__) && !$transitionToHistoryMarker) { $this->_currentState->start(); if (Stagehand_FSM_Error::hasErrors()) { $return = null; return $return; } } if (!$this->_isSpecialEvent($eventName)) { $this->_processEvent(STAGEHAND_FSM_EVENT_ENTRY, $event->getTransitionToHistoryMarker()); if (Stagehand_FSM_Error::hasErrors()) { $return = null; return $return; } } if (!$this->_isSpecialEvent($eventName)) { $this->_processEvent(STAGEHAND_FSM_EVENT_DO, $event->getTransitionToHistoryMarker()); if (Stagehand_FSM_Error::hasErrors()) { $return = null; return $return; } } return $this->_currentState; }