Пример #1
0
 /**
  * Adds the given state to the state machine setup.
  *
  * @param StateInterface $state
  *
  * @return StateMachineBuilderInterface
  */
 public function addState(StateInterface $state)
 {
     $state_name = $state->getName();
     if (isset($this->states[$state_name])) {
         throw new VerificationError(sprintf('A state with the name "%s" already has been added.' . ' State names must be unique within each StateMachine.', $state_name));
     }
     $this->states[$state_name] = $state;
     return $this;
 }
Пример #2
0
 /**
  * Employs an active-state specific verification.
  *
  * @param StateInterface $state
  * @param int $transition_count Number of transitions attached to the given state.
  *
  * @throws VerificationError
  */
 protected function verifyActiveState(StateInterface $state, $transition_count)
 {
     if ($transition_count === 0) {
         throw new VerificationError(sprintf('State "%s" is expected to have at least one transition.' . ' Only "%s" states are permitted to have no transitions.', $state->getName(), StateInterface::TYPE_FINAL));
     }
 }
Пример #3
0
 /**
  * Executes the onEnter handler for the current state before applying a transition.
  *
  * @param StatefulSubjectInterface $subject
  * @param StateInterface $current_state
  */
 protected function enterState(StatefulSubjectInterface $subject, StateInterface $next_state)
 {
     $next_state->onEntry($subject);
 }
Пример #4
0
 /**
  * Creates a specific dot-graph node that represents the given state.
  *
  * @param StateMachineInterface $state_machine
  * @param StateInterface $state
  *
  * @return string
  */
 protected function createStateNode(StateMachineInterface $state_machine, StateInterface $state)
 {
     $state_name = $state->getName();
     $attributes = [sprintf('label="%s"', $state_name), sprintf('fontname="%s"', $this->getStyle('state_node.fontname', self::STATE_NODE_FONTNAME)), sprintf('fontsize="%s"', $this->getStyle('state_node.fontsize', self::STATE_NODE_FONTSIZE)), sprintf('fontcolor="%s"', $this->getStyle('state_node.fontcolor', self::STATE_NODE_FONTCOLOR)), sprintf('color="%s"', $this->getStyle('state_node.color', self::STATE_NODE_COLOR))];
     if ($state->isFinal()) {
         $attributes[] = 'style="bold"';
     }
     if (!$state_machine->isEventState($state_name) && !$state->isFinal()) {
         $attributes[] = 'shape="parallelogram"';
     }
     return sprintf('%s [%s]', $this->node_id_map[$state_name], implode(' ', $attributes));
 }
Пример #5
0
 /**
  * Sets the current state name.
  * Is called when the state machine enters a new state
  *
  * @param StateInterface $state
  */
 public function onStateEntry(StateInterface $state)
 {
     $this->current_state_name = $state->getName();
 }