cvs: pear /FSM FSM.php
| From: | Jon Parise | Date: | Sun, 29 Dec 2002 21:53:25 +0000 |
| Subject: | cvs: pear /FSM FSM.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-7984@lists.php.net to get a copy of this message | ||
jon Sun Dec 29 16:53:25 2002 EDT
Modified files:
/pear/FSM FSM.php
Log:
Callback functions may now optionally return the name of a new state.
Index: pear/FSM/FSM.php
diff -u pear/FSM/FSM.php:1.2 pear/FSM/FSM.php:1.3
--- pear/FSM/FSM.php:1.2 Sat Nov 16 15:45:41 2002
+++ pear/FSM/FSM.php Sun Dec 29 16:53:25 2002
@@ -16,7 +16,7 @@
* | Authors: Jon Parise <jon@php.net> |
* +----------------------------------------------------------------------+
*
- * $Id: FSM.php,v 1.2 2002/11/16 20:45:41 jon Exp $
+ * $Id: FSM.php,v 1.3 2002/12/29 21:53:25 jon Exp $
*/
/**
@@ -27,7 +27,7 @@
* Automata (a finite state machine with memory).
*
* @author Jon Parise <jon@php.net>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @package FSM
*/
@@ -227,6 +227,9 @@
* provided symbol and the current state. If no valid transition is found,
* process() returns immediately.
*
+ * The action callback may return the name of a new state. If one is
+ * returned, the current state will be updated to the new value.
+ *
* If no action is defined for the transition, only the state will be
* changed.
*
@@ -243,13 +246,18 @@
return;
}
+ /* Update the current state to this transition's exit state. */
+ $this->_currentState = $transition[0];
+
/* If an action for this transition has been specified, execute it. */
if (!empty($transition[1])) {
- call_user_func($transition[1], $symbol, &$this->_payload);
- }
+ $state = call_user_func($transition[1], $symbol, &$this->_payload);
- /* Update the current state to this transition's exit state. */
- $this->_currentState = $transition[0];
+ /* If a new state was returned, update the current state. */
+ if (!empty($state) && is_string($state)) {
+ $this->_currentState = $state;
+ }
+ }
}
/**