Beispiel #1
0
 /**
  * Checks is transition allowed (by guards etc)
  *
  * @param ContextInterface    $context
  * @param TransitionInterface $transition
  * @return bool
  */
 private function isTransitionAllowed(ContextInterface $context, TransitionInterface $transition)
 {
     if (!$transition->hasGuard()) {
         return true;
     }
     return call_user_func($transition->getGuard(), $context);
 }
Beispiel #2
0
 /**
  * Add transition
  * 
  * @param \FSM\Transition\TransitionInterface $transition
  * @param \FSM\State\StateInterface $sourceState
  * @param \FSM\State\StateInterface $targetState
  * @return \FSM\AbstractClient
  */
 public function addTransition(TransitionInterface $transition, StateInterface $sourceState, StateInterface $targetState)
 {
     if (!$transition->getName()) {
         throw new ClientInitializationException("Can not register transition without a name.");
     } elseif ($this->getTransitionByName($transition->getName()) !== null) {
         throw new ClientInitializationException("Can not register transition. The transition with the same name already exists.");
     } elseif (!array_search($sourceState, $this->states) || !array_search($targetState, $this->states)) {
         throw new ClientInitializationException("Can not register transition. Wrong state selected as an end point.");
     }
     // Add source and target states
     try {
         $transition->setSourceState($sourceState);
         $transition->setTargetState($targetState);
     } catch (\Exception $ex) {
         throw new ComponentConfigurationException("Can not assign source", 0, $ex);
     }
     $this->transitions[$transition->getName()] = $transition;
     return $this;
 }