Added implementation changes, fixed to make test pass

This commit is contained in:
l3l0 2012-06-29 20:13:46 +02:00
parent 9c5105d8da
commit bfc8c9ce2d
4 changed files with 52 additions and 22 deletions

View file

@ -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');
}
}
}

View file

@ -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;

View file

@ -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];

View file

@ -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);
}