コード例 #1
0
ファイル: AbstractClient.php プロジェクト: zinovyev/php-fsm
 /**
  * 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;
 }