Exemplo n.º 1
0
 /**
  * Create a new invalid model state.
  *
  * @param ModelInterface  $model
  * @param string          $processName
  * @param string          $stepName
  * @param ViolationList   $violationList
  * @param null|ModelState $previous
  *
  * @return ModelState
  */
 public function newModelStateError(ModelInterface $model, $processName, $stepName, ViolationList $violationList, $previous = null)
 {
     $modelState = $this->createModelState($model, $processName, $stepName, $previous);
     $modelState->setSuccessful(false);
     $modelState->setErrors($violationList->toArray());
     $this->om->persist($modelState);
     $this->om->flush($modelState);
     return $modelState;
 }
Exemplo n.º 2
0
 /**
  * Reach the given step.
  *
  * @param  ModelInterface $model
  * @param  Step $step
  * @param  ModelState $currentModelState
  * @return ModelState
  */
 protected function reachStep(ModelInterface $model, Step $step, ModelState $currentModelState = null)
 {
     try {
         $this->checkCredentials($model, $step);
     } catch (AccessDeniedException $e) {
         $violations = new ViolationList();
         $violations->add(new Violation($e->getMessage()));
         $modelState = $this->storage->newModelStateError($model, $this->process->getName(), $step->getName(), $violations, $currentModelState);
         $eventName = sprintf('%s.%s.bad_credentials', $this->process->getName(), $step->getName());
         $this->dispatcher->dispatch($eventName, new StepEvent($step, $model, $modelState));
         if ($step->getOnInvalid()) {
             $step = $this->getProcessStep($step->getOnInvalid());
             $modelState = $this->reachStep($model, $step);
         }
         return $modelState;
     }
     $event = new ValidateStepEvent($step, $model, new ViolationList());
     $eventName = sprintf('%s.%s.validate', $this->process->getName(), $step->getName());
     $this->dispatcher->dispatch($eventName, $event);
     if (0 === count($event->getViolationList())) {
         $modelState = $this->storage->newModelStateSuccess($model, $this->process->getName(), $step->getName(), $currentModelState);
         // update model status
         if ($step->hasModelStatus()) {
             list($method, $constant) = $step->getModelStatus();
             $model->{$method}(constant($constant));
         }
         $eventName = sprintf('%s.%s.reached', $this->process->getName(), $step->getName());
         $this->dispatcher->dispatch($eventName, new StepEvent($step, $model, $modelState));
     } else {
         $modelState = $this->storage->newModelStateError($model, $this->process->getName(), $step->getName(), $event->getViolationList(), $currentModelState);
         $eventName = sprintf('%s.%s.validation_fail', $this->process->getName(), $step->getName());
         $this->dispatcher->dispatch($eventName, new StepEvent($step, $model, $modelState));
         if ($step->getOnInvalid()) {
             $step = $this->getProcessStep($step->getOnInvalid());
             $modelState = $this->reachStep($model, $step);
         }
     }
     return $modelState;
 }
Exemplo n.º 3
0
 /**
  * Proxy method to add a violation.
  *
  * @param $message
  */
 public function addViolation($message)
 {
     $this->violationList->add(new Violation($message));
 }