diff --git a/src/Sylius/Bundle/FlowBundle/Process/Builder/ProcessBuilder.php b/src/Sylius/Bundle/FlowBundle/Process/Builder/ProcessBuilder.php index b327c5a5a6..266272bacf 100644 --- a/src/Sylius/Bundle/FlowBundle/Process/Builder/ProcessBuilder.php +++ b/src/Sylius/Bundle/FlowBundle/Process/Builder/ProcessBuilder.php @@ -69,6 +69,8 @@ class ProcessBuilder implements ProcessBuilderInterface */ public function add($name, $step) { + $this->assertHasProcess(); + if (is_string($step)) { $step = $this->loadStep($step); } @@ -93,6 +95,8 @@ class ProcessBuilder implements ProcessBuilderInterface */ public function remove($name) { + $this->assertHasProcess(); + $this->process->removeStep($name); } @@ -101,6 +105,8 @@ class ProcessBuilder implements ProcessBuilderInterface */ public function has($name) { + $this->assertHasProcess(); + return $this->process->hasStep($name); } @@ -109,6 +115,8 @@ class ProcessBuilder implements ProcessBuilderInterface */ public function setDisplayRoute($route) { + $this->assertHasProcess(); + $this->process->setDisplayRoute($route); return $this; @@ -119,6 +127,8 @@ class ProcessBuilder implements ProcessBuilderInterface */ public function setForwardRoute($route) { + $this->assertHasProcess(); + $this->process->setForwardRoute($route); return $this; @@ -129,6 +139,8 @@ class ProcessBuilder implements ProcessBuilderInterface */ public function setRedirect($redirect) { + $this->assertHasProcess(); + $this->process->setRedirect($redirect); return $this; @@ -139,6 +151,8 @@ class ProcessBuilder implements ProcessBuilderInterface */ public function validate(\Closure $validator) { + $this->assertHasProcess(); + $this->process->setValidator($validator); return $this; @@ -167,4 +181,16 @@ class ProcessBuilder implements ProcessBuilderInterface return $this->steps[$alias]; } + + /** + * If process do not exists, throw exception. + * + * @throws \RuntimeException + */ + protected function assertHasProcess() + { + if (!$this->process) { + throw new \RuntimeException('Process is not set'); + } + } } diff --git a/src/Sylius/Bundle/FlowBundle/Process/Coordinator/Coordinator.php b/src/Sylius/Bundle/FlowBundle/Process/Coordinator/Coordinator.php index c937ba023e..904d09b2a7 100644 --- a/src/Sylius/Bundle/FlowBundle/Process/Coordinator/Coordinator.php +++ b/src/Sylius/Bundle/FlowBundle/Process/Coordinator/Coordinator.php @@ -172,17 +172,20 @@ class Coordinator implements CoordinatorInterface */ protected function redirectToStepDisplayAction(ProcessInterface $process, StepInterface $step) { - $url = $this->router->generate('sylius_flow_display', array( - 'scenarioAlias' => $process->getScenarioAlias(), - 'stepName' => $step->getName() - )); if (null !== $route = $process->getDisplayRoute()) { $url = $this->router->generate($route, array( 'stepName' => $step->getName() )); + + return new RedirectResponse($url); } + $url = $this->router->generate('sylius_flow_display', array( + 'scenarioAlias' => $process->getScenarioAlias(), + 'stepName' => $step->getName() + )); + return new RedirectResponse($url); } @@ -197,7 +200,7 @@ class Coordinator implements CoordinatorInterface { $processScenario = $this->loadScenario($scenarioAlias); - $process = $this->builder->build($processScenario, $scenarioAlias); + $process = $this->builder->build($processScenario); $process->setScenarioAlias($scenarioAlias); return $process; diff --git a/src/Sylius/Bundle/FlowBundle/Process/Process.php b/src/Sylius/Bundle/FlowBundle/Process/Process.php index 82f69d2e89..42ee913fae 100644 --- a/src/Sylius/Bundle/FlowBundle/Process/Process.php +++ b/src/Sylius/Bundle/FlowBundle/Process/Process.php @@ -98,7 +98,9 @@ class Process implements ProcessInterface */ public function setSteps(array $steps) { - $this->steps = $steps; + foreach ($steps as $name => $step) { + $this->addStep($name, $step); + } } /** @@ -109,21 +111,13 @@ class Process implements ProcessInterface return $this->orderedSteps; } - /** - * {@inheritdoc} - */ - public function setOrderedSteps(array $orderedSteps) - { - $this->orderedSteps = $orderedSteps; - } - /** * {@inheritdoc} */ public function getStepByIndex($index) { if (!isset($this->orderedSteps[$index])) { - throw new \InvalidArgumentException(spritnf('Step with index %d. does not exist', $index)); + throw new \InvalidArgumentException(sprintf('Step with index %d. does not exist', $index)); } return $this->orderedSteps[$index]; diff --git a/src/Sylius/Bundle/FlowBundle/Process/ProcessInterface.php b/src/Sylius/Bundle/FlowBundle/Process/ProcessInterface.php index b314e4bfa9..6b32edf3cf 100644 --- a/src/Sylius/Bundle/FlowBundle/Process/ProcessInterface.php +++ b/src/Sylius/Bundle/FlowBundle/Process/ProcessInterface.php @@ -57,13 +57,6 @@ interface ProcessInterface */ function getOrderedSteps(); - /** - * Set ordered steps. - * - * @param array $steps - */ - function setOrderedSteps(array $steps); - /** * Get first process step. * @@ -164,4 +157,18 @@ interface ProcessInterface * @param string $route */ function setForwardRoute($route); + + /** + * Get step by index/order + * + * @return StepInterface + */ + function getStepByIndex($index); + + /** + * Get step by name + * + * @return StepInterface + */ + function getStepByName($index); }