0) { return true; } return false; } function cb4($beta) { if($beta < 0) { return true; } return false; } function cb5($beta) { if($beta > 0) { return true; } return false; } function step1 () { echo "I'm step one".PHP_EOL; } function step2 () { echo "I'm step two".PHP_EOL; } function step3 () { echo "I'm step three".PHP_EOL; } function step4 () { echo "I'm step four".PHP_EOL; } function step5 () { echo "I'm step five".PHP_EOL; } function step6 () { echo "I'm step six".PHP_EOL; } // create a new state machine $sm = new Fr\RetailMeNot\Cloud\StateMachine\StateMachine(); // affect a new environment $sm->setProperty('alpha', 1); $sm->setProperty('beta', -1); // create states $start = new Fr\RetailMeNot\Cloud\StateMachine\State('START', 'Fr\RetailMeNot\Cloud\StateMachine\CallbackRegistry::startCallback'); $step1 = new Fr\RetailMeNot\Cloud\StateMachine\State('step1', 'step1'); $step2 = new Fr\RetailMeNot\Cloud\StateMachine\State('step2', 'step2'); $step3 = new Fr\RetailMeNot\Cloud\StateMachine\State('step3', 'step3'); $step4 = new Fr\RetailMeNot\Cloud\StateMachine\State('step4', 'step4'); $step5 = new Fr\RetailMeNot\Cloud\StateMachine\State('step5', 'step5'); $step6 = new Fr\RetailMeNot\Cloud\StateMachine\State('step6', 'step6'); $stop = new Fr\RetailMeNot\Cloud\StateMachine\State('STOP', 'Fr\RetailMeNot\Cloud\StateMachine\CallbackRegistry::stopCallback'); // create transition $t0 = new Fr\RetailMeNot\Cloud\StateMachine\Transition('t0', 'cb0'); $t1 = new Fr\RetailMeNot\Cloud\StateMachine\Transition('t1', 'cb1', array('alpha')); $t2 = new Fr\RetailMeNot\Cloud\StateMachine\Transition('t2', 'cb2', array('alpha')); $t3 = new Fr\RetailMeNot\Cloud\StateMachine\Transition('t3', 'cb3', array('alpha')); $t4 = new Fr\RetailMeNot\Cloud\StateMachine\Transition('t4', 'cb4', array('beta')); $t5 = new Fr\RetailMeNot\Cloud\StateMachine\Transition('t5', 'cb5', array('beta')); // create graph $sm->addStep($start, $step1, $t0); // alpha choice $sm->addStep($step1, $step2, $t1); $sm->addStep($step1, $step3, $t2); $sm->addStep($step1, $step4, $t3); // step2 loop $sm->addStep($step2, $step1, $t0); // step3 end $sm->addStep($step3, $stop, $t0); // beta choice $sm->addStep($step4, $step5, $t4); $sm->addStep($step4, $step6, $t5); // ends $sm->addStep($step5, $stop, $t0); $sm->addStep($step6, $stop, $t0); // define current step and end state $sm->setCurretState($start); $sm->setEndState($stop); // test $sm->start(); while($sm->next());