Does anybody know a finite state machine
that has guard feature in PHP ?
Using PEAR's FSM (usage example), you can use the action callback to return the next state if the guard fails, like so:
$payload = '';
$fsm = new FSM('STATE1', $payload);
function guard1($symbol, $payload) {
if ($payload == 'something') {
// Guard success, allow transition
return;
}
else {
// Guard fail, return to previous state
return 'STATE1';
}
}
$fsm->addTransition('SYMBOL1', 'STATE1', 'STATE2', 'guard1');
$fsm->process('SYMBOL1');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With