Example #1
0
 /**
  * @expectedException \Michcald\Fsm\Exception\Accessor\InvalidStatefulClassException
  */
 public function testInvalidStatefulClassValue()
 {
     $fsm = new Fsm('my_fsm');
     $fsm->setStates(array(new State('s1', true), new State('s2'), new State('s3', false, true)))->setTransitions(array(new Transition('t1', 's1', 's2'), new Transition('t2', 's2', 's3')));
     $validator = new FsmValidator();
     $validator->validate($fsm);
     $obj = new Document();
     $obj->setMyState('s1');
     $accessor = new FsmAccessor($fsm, $validator, 'Document2', 'myState');
     $accessor->doTransition($obj, 't1');
 }
Example #2
0
    {
        $this->myState = $state;
        return $this;
    }
    public function getMyState()
    {
        return $this->myState;
    }
}
// definig the FSM
$fsm = new Fsm('fsm1');
$fsm->setStates(array(new State('s1', true), new State('s2'), new State('s3'), new State('s4', false, true)));
$fsm->setTransitions(array(new Transition('t1', 's1', 's2'), new Transition('t2', 's1', 's3'), new Transition('t3', 's3', 's1'), new Transition('t4', 's2', 's4')));
$doc = new Document();
$doc->setMyState('s1');
$accessor = new FsmAccessor($fsm, new FsmValidator(), 'Document', 'myState');
try {
    if ($accessor->isInitialState($doc)) {
        printf('The object is in the INITIAL state%s', PHP_EOL);
    }
    $accessor->doTransition($doc, 't1');
    printTransition($fsm->getTransitionByName('t1'));
    $accessor->doTransition($doc, 't4');
    printTransition($fsm->getTransitionByName('t4'));
    if ($accessor->isFinalState($doc)) {
        printf('The object has reached an FINAL state%s', PHP_EOL);
    }
} catch (\Exception $e) {
    throw $e;
}
function printTransition(Transition $transition)