Exemplo n.º 1
0
 /**
  * @param \ArrayAccess   $context
  * @param EventInterface $event
  */
 protected function doCheckTransitions(\ArrayAccess $context, EventInterface $event = null)
 {
     try {
         $transitions = $this->currentState->getTransitions();
         $activeTransitions = new ActiveTransitionFilter($transitions, $this->getSubject(), $context, $event);
         $this->selectedTransition = $this->transitonSelector->selectTransition($activeTransitions);
         if ($this->selectedTransition) {
             $targetState = $this->selectedTransition->getTargetState();
             if ($this->currentState != $targetState) {
                 $this->lastState = $this->currentState;
                 $this->currentState = $targetState;
                 $this->notify();
                 $this->selectedTransition = null;
                 $this->lastState = null;
             }
             $this->checkTransitions();
         }
     } catch (\Exception $exception) {
         $message = 'Exception was thrown when doing a transition from current state "' . $this->currentState->getName() . '"';
         if ($this->currentEvent instanceof NamedInterface) {
             $message .= ' with event "' . $this->currentEvent->getName() . '"';
         }
         throw new \RuntimeException($message, 0, $exception);
     }
 }
Exemplo n.º 2
0
 /**
  *
  * @param ArrayAccess    $context
  * @param EventInterface $event
  */
 protected function doCheckTransitions(ArrayAccess $context, EventInterface $event = null)
 {
     $transitions = $this->currentState->getTransitions();
     $activeTransitions = new ActiveTransitionFilter($transitions, $this->getSubject(), $context, $event);
     $this->selectedTransition = $this->transitonSelector->selectTransition($activeTransitions);
     if ($this->selectedTransition) {
         $this->beforeTransition($this->getSubject(), $this->selectedTransition->getTargetState()->getName());
         $this->currentState = $this->selectedTransition->getTargetState();
         $this->notify();
         $this->selectedTransition = null;
         $this->checkTransitions();
     }
 }
Exemplo n.º 3
0
 /**
  * @param StateInterface     $sourceState
  * @param StateInterface     $targetState
  * @param string             $eventName
  * @param ConditionInterface $condition
  *
  * @return TransitionInterface
  */
 protected function findTransition(StateInterface $sourceState, StateInterface $targetState, $eventName = null, ConditionInterface $condition = null)
 {
     $conditionName = $condition ? $condition->getName() : null;
     /* @var $transition TransitionInterface */
     foreach ($sourceState->getTransitions() as $transition) {
         $hasSameTargetState = $transition->getTargetState() === $targetState;
         $hasSameCondition = $transition->getConditionName() == $conditionName;
         $hasSameEvent = $transition->getEventName() == $eventName;
         if ($hasSameTargetState && $hasSameCondition && $hasSameEvent) {
             return $transition;
         }
     }
 }