예제 #1
0
 /**
  * Moves the current token to the next node of the workflow.
  *
  * @param ContextInterface $context
  *
  * @return Workflow
  *
  * @throws Exception\NotInitializedWorkflowException
  * @throws Exception\NoOpenTransitionException
  * @throws Exception\MoreThanOneOpenTransitionException
  */
 public function next(ContextInterface $context)
 {
     if (null === $this->current) {
         throw new Exception\NotInitializedWorkflowException();
     }
     $transitions = $this->current->getOpenTransitions($context);
     if (0 === count($transitions)) {
         throw new Exception\NoOpenTransitionException();
     } elseif (1 < count($transitions)) {
         throw new Exception\MoreThanOneOpenTransitionException();
     }
     $transition = array_pop($transitions);
     $token = $transition->getDestination()->getName();
     $this->initialize($token);
     $this->eventDispatcher->dispatch($token, new Event($context, $token));
     return $this;
 }
예제 #2
0
 /**
  * Opens a workflow.
  *
  * @param string $src
  * @param SpecificationInterface $spec
  *
  * @return Builder
  */
 public function open($src, SpecificationInterface $spec)
 {
     $this->start = $this->nodes->get(uniqid());
     $this->start->addTransition($this->nodes->get($src), $spec);
     return $this;
 }