Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function validate($validator)
 {
     $this->assertHasProcess();
     if ($validator instanceof \Closure) {
         $validator = $this->container->get('sylius.process.validator')->setValidation($validator);
     }
     if (!$validator instanceof ProcessValidatorInterface) {
         throw new \InvalidArgumentException();
     }
     $this->process->setValidator($validator);
     return $this;
 }
Beispiel #2
0
 /**
  * @param ProcessInterface $process
  * @param string           $scenarioAlias
  *
  * @return RedirectResponse
  */
 protected function goToLastValidStep(ProcessInterface $process, $scenarioAlias)
 {
     //the step we are supposed to display was not found in the history.
     if (null === $this->context->getPreviousStep()) {
         //there is no previous step go to start
         return $this->start($scenarioAlias);
     }
     //we will go back to previous step...
     $history = $this->context->getStepHistory();
     if (empty($history)) {
         //there is no history
         return $this->start($scenarioAlias);
     }
     $step = $process->getStepByName(end($history));
     $this->context->initialize($process, $step);
     return $this->redirectToStepDisplayAction($process, $step);
 }
Beispiel #3
0
 /**
  * Redirect to step display action.
  *
  * @param ProcessInterface $process
  * @param StepInterface    $step
  * @param ParameterBag     $queryParameters
  *
  * @return RedirectResponse
  */
 protected function redirectToStepDisplayAction(ProcessInterface $process, StepInterface $step, ParameterBag $queryParameters = null)
 {
     $this->context->addStepToHistory($step->getName());
     if (null !== ($route = $process->getDisplayRoute())) {
         $url = $this->router->generate($route, array_merge($process->getDisplayRouteParams(), array('stepName' => $step->getName())));
         return new RedirectResponse($url);
     }
     // Default parameters for display route
     $routeParameters = array('scenarioAlias' => $process->getScenarioAlias(), 'stepName' => $step->getName());
     if (null !== $queryParameters) {
         $routeParameters = array_merge($queryParameters->all(), $routeParameters);
     }
     $url = $this->router->generate('sylius_flow_display', $routeParameters);
     return new RedirectResponse($url);
 }
Beispiel #4
0
 /**
  * Calculates progress based on current step index.
  *
  * @param int $currentStepIndex
  */
 protected function calculateProgress($currentStepIndex)
 {
     $this->progress = floor(($currentStepIndex + 1) / $this->process->countSteps() * 100);
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function setNextStepByName($stepName)
 {
     $this->nextStep = $this->process->getStepByName($stepName);
 }
Beispiel #6
0
 function it_rewind_history($storage, ProcessInterface $process, StepInterface $currentStep, StepInterface $previousStep, StepInterface $nextStep)
 {
     $currentStep->getName()->willReturn('step_two');
     $process->getScenarioAlias()->shouldBeCalled();
     $storage->initialize(Argument::type('string'))->shouldBeCalled();
     $process->getOrderedSteps()->shouldBeCalled()->willReturn(array($previousStep, $currentStep, $nextStep));
     $process->countSteps()->shouldBeCalled()->willReturn(2);
     $this->initialize($process, $currentStep);
     $storage->get("history", array())->shouldBeCalled()->willreturn(array("step_one", "step_two", "step_three"));
     $storage->set('history', array('step_one', 'step_two'))->shouldBeCalled();
     $this->rewindHistory();
 }