Beispiel #1
0
 /**
  * @see MetaborStd\Statemachine.TransitionInterface::isActive()
  */
 public function isActive($subject, \ArrayAccess $context, EventInterface $event = null)
 {
     if ($event) {
         $result = $event->getName() == $this->eventName;
     } else {
         $result = is_null($this->eventName);
     }
     if ($this->condition) {
         $result = $result && $this->condition->checkCondition($subject, $context);
     }
     return $result;
 }
 /**
  * @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);
     }
 }
 /**
  * @param EventInterface $event
  * @param callable       $command
  */
 protected function addCommand(EventInterface $event, $command)
 {
     $callback = new Callback($command);
     $observer = new ObserverCallback($callback);
     $event->attach($observer);
 }
Beispiel #4
0
 /**
  * @param EventInterface $event
  *
  * @return string
  */
 protected function convertObserverToString(EventInterface $event)
 {
     $observers = array();
     foreach ($event->getObservers() as $observer) {
         $observers[] = $this->stringConverter->convertToString($observer);
     }
     return implode(', ', $observers);
 }