Exemplo n.º 1
0
 /**
  * get registered state or throw exception else
  *
  * @param string $name
  * @return State
  */
 public function getState($name)
 {
     if (!array_key_exists($name, $this->states)) {
         throw WorkflowEngineException::youTryUseNonExistingState($name, array_keys($this->states));
     }
     return $this->states[$name];
 }
 /**
  * Получает Transition Specification для перемещения сущности из oldState в newState
  *
  * @param string $oldStateName
  * @param string $newStateName
  * @return null|TransitionSpecification
  */
 public function getTransitionSpecification($oldStateName, $newStateName)
 {
     $foundedTransitionSpecification = null;
     foreach ($this->transitionsSpecifications as $transition) {
         if ($transition->getOldState()->getName() === $oldStateName && $transition->getNewState()->getName() === $newStateName) {
             $foundedTransitionSpecification = $transition;
         }
     }
     if (is_null($foundedTransitionSpecification)) {
         throw WorkflowEngineException::cantFindTransitionSpecification($oldStateName, $newStateName, array_keys($this->getTransitionsSpecifications()));
     }
     return $foundedTransitionSpecification;
 }