Ejemplo n.º 1
0
 /**
  * Creates a specific dot-graph edge for the given state-transition.
  *
  * @param TransitionInterface $transition
  * @param string $state_name
  * @param string $event_name
  *
  * @return string
  */
 protected function createEdge(TransitionInterface $transition, $state_name, $event_name)
 {
     $from_node = $this->node_id_map[$state_name];
     $to_node = $this->node_id_map[$transition->getOutgoingStateName()];
     $transition_label = $event_name === StateMachine::SEQ_TRANSITIONS_KEY ? '' : $event_name;
     if ($transition->hasGuard()) {
         $transition_label .= $transition->getGuard();
     }
     $attributes = [sprintf('label="%s"', trim(addslashes($transition_label))), sprintf('fontname="%s"', $this->getStyle('edge.fontname', self::EDGE_FONTNAME)), sprintf('fontsize="%s"', $this->getStyle('edge.fontsize', self::EDGE_FONTSIZE)), sprintf('fontcolor="%s"', $this->getStyle('edge.fontcolor', self::EDGE_FONTCOLOR))];
     $attributes[] = sprintf('color="%s"', $this->getEdgeColor($event_name));
     return sprintf('%s -> %s [%s]', $from_node, $to_node, implode(' ', $attributes));
 }
Ejemplo n.º 2
0
 /**
  * Checks if the given subject may proceed trough the given transition.
  *
  * @param StatefulSubjectInterface $subject
  * @param TransitionInterface $transition
  *
  * @return bool
  */
 protected function mayProceed(StatefulSubjectInterface $subject, TransitionInterface $transition)
 {
     if (!$transition->hasGuard()) {
         return true;
     }
     return $transition->getGuard()->accept($subject);
 }
Ejemplo n.º 3
0
 /**
  * Adds a single transition to the state machine setup for a given event.
  *
  * @param TransitionInterface $transition
  * @param string $event_name If the event name is omitted, then the transition will act as sequential.
  *
  * @return StateMachineBuilderInterface
  */
 public function addTransition(TransitionInterface $transition, $event_name = '')
 {
     $transition_key = $event_name ?: StateMachine::SEQ_TRANSITIONS_KEY;
     foreach ($transition->getIncomingStateNames() as $state_name) {
         $this->allocateTransitionKey($state_name, $transition_key);
         if (in_array($transition, $this->transitions[$state_name][$transition_key], true)) {
             throw new VerificationError('Adding the same transition instance twice is not supported.');
         }
         $this->transitions[$state_name][$transition_key][] = $transition;
     }
     return $this;
 }