/**
  * Return compiled machine
  *
  * @return Machine Machine instance
  */
 public function getMachine()
 {
     $transitionChain = TransitionChain::create();
     $transitionChain->addTransition(new Transition('pay', new State('unpaid'), new State('paid')))->addTransition(new Transition('revise', new State('unpaid'), new State('revised')))->addTransition(new Transition('ship', new State('revised'), new State('shipped')));
     $machine = new Machine('id', $transitionChain, 'unpaid');
     return $machine;
 }
Beispiel #2
0
 /**
  * Compile next states of each state.
  *
  * @param TransitionChain $transitionChain Transition chain
  *
  * @return $this Self object
  *
  * @throws StateNotValidException state is not valid
  */
 private function checkStates(TransitionChain $transitionChain)
 {
     /**
      * @var Transition $transition
      */
     foreach ($transitionChain->getTransitions() as $transition) {
         $initialStateName = $transition->getStart()->getName();
         if ($initialStateName === $this->pointOfEntry) {
             continue;
         }
         if (!$this->transitionChain->getTransitionsByFinalState($initialStateName)) {
             throw new StateNotValidException($initialStateName);
         }
     }
     return $this;
 }
Beispiel #3
0
 /**
  * Get available states given a start state
  *
  * @param string $startStateName Start state name
  *
  * @return array Set of states
  */
 public function getAvailableStates($startStateName)
 {
     return array_filter($this->transitionChain->getTransitions(), function (Transition $transition) use($startStateName) {
         return $transition->getStart()->getName() === $startStateName;
     });
 }