Example #1
0
 /**
  * @param TransitionInterface $transition
  *
  * @return int
  */
 protected function calculcateScore(TransitionInterface $transition)
 {
     $score = 0;
     if ($transition->getEventName()) {
         $score += 2;
     }
     if ($transition->getConditionName()) {
         ++$score;
     }
     return $score;
 }
 /**
  * @param TransitionInterface $sourceTransition
  *
  * @throws \InvalidArgumentException
  *
  * @return \Metabor\Statemachine\Transition
  */
 protected function createTransition(TransitionInterface $sourceTransition)
 {
     $targetStateName = $sourceTransition->getTargetState()->getName();
     $targetState = $this->findOrCreateState($targetStateName);
     $this->mergeMetadata($sourceTransition->getTargetState(), $targetState);
     $eventName = $sourceTransition->getEventName();
     if ($sourceTransition->getConditionName()) {
         if ($sourceTransition instanceof Transition) {
             $condition = $sourceTransition->getCondition();
         } else {
             throw new \InvalidArgumentException('Overwrite this method to implement a different type!');
         }
     } else {
         $condition = null;
     }
     return new Transition($targetState, $eventName, $condition);
 }
Example #3
0
 /**
  * @param TransitionInterface $transition
  *
  * @return string
  */
 protected function getTransitionLabel(StateInterface $state, TransitionInterface $transition)
 {
     $labelParts = array();
     $eventName = $transition->getEventName();
     if ($eventName) {
         $labelParts[] = 'E: ' . $eventName;
         $event = $state->getEvent($eventName);
         $observerName = $this->convertObserverToString($event);
         if ($observerName) {
             $labelParts[] = 'C: ' . $observerName;
         }
     }
     $conditionName = $transition->getConditionName();
     if ($conditionName) {
         $labelParts[] = 'IF: ' . $conditionName;
     }
     if ($transition instanceof WeightedInterface) {
         $labelParts[] = 'W: ' . $transition->getWeight();
     }
     $label = implode(PHP_EOL, $labelParts);
     return $label;
 }
Example #4
0
 /**
  * @param  TransitionInterface $transition
  * @return string
  */
 protected function getTransitionLabel(StateInterface $state, TransitionInterface $transition)
 {
     $labelParts = array();
     $eventName = $transition->getEventName();
     if ($eventName) {
         $labelParts[] = 'E: ' . $eventName;
         $event = $state->getEvent($eventName);
         $observers = $event->getObservers();
         $observerName = implode(', ', iterator_to_array($observers, false));
         if ($observerName) {
             $labelParts[] = 'C: ' . $observerName;
         }
     }
     $conditionName = $transition->getConditionName();
     if ($conditionName) {
         $labelParts[] = 'IF: ' . $conditionName;
     }
     $label = implode(PHP_EOL, $labelParts);
     return $label;
 }
 /**
  * @param TransitionInterface $sourceTransition
  *
  * @throws \InvalidArgumentException
  *
  * @return \Metabor\Statemachine\Transition
  */
 protected function createTransition(TransitionInterface $sourceTransition)
 {
     $targetStateName = $sourceTransition->getTargetState()->getName();
     $targetState = $this->findOrCreateState($targetStateName);
     $this->mergeMetadata($sourceTransition->getTargetState(), $targetState);
     $eventName = $sourceTransition->getEventName();
     $condition = $this->createCondition($sourceTransition);
     $transition = new Transition($targetState, $eventName, $condition);
     if ($sourceTransition instanceof WeightedInterface) {
         $transition->setWeight($sourceTransition->getWeight());
     }
     return $transition;
 }