mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Added implementation changes, fixed to make test pass
This commit is contained in:
parent
9c5105d8da
commit
bfc8c9ce2d
4 changed files with 52 additions and 22 deletions
|
|
@ -69,6 +69,8 @@ class ProcessBuilder implements ProcessBuilderInterface
|
||||||
*/
|
*/
|
||||||
public function add($name, $step)
|
public function add($name, $step)
|
||||||
{
|
{
|
||||||
|
$this->assertHasProcess();
|
||||||
|
|
||||||
if (is_string($step)) {
|
if (is_string($step)) {
|
||||||
$step = $this->loadStep($step);
|
$step = $this->loadStep($step);
|
||||||
}
|
}
|
||||||
|
|
@ -93,6 +95,8 @@ class ProcessBuilder implements ProcessBuilderInterface
|
||||||
*/
|
*/
|
||||||
public function remove($name)
|
public function remove($name)
|
||||||
{
|
{
|
||||||
|
$this->assertHasProcess();
|
||||||
|
|
||||||
$this->process->removeStep($name);
|
$this->process->removeStep($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,6 +105,8 @@ class ProcessBuilder implements ProcessBuilderInterface
|
||||||
*/
|
*/
|
||||||
public function has($name)
|
public function has($name)
|
||||||
{
|
{
|
||||||
|
$this->assertHasProcess();
|
||||||
|
|
||||||
return $this->process->hasStep($name);
|
return $this->process->hasStep($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,6 +115,8 @@ class ProcessBuilder implements ProcessBuilderInterface
|
||||||
*/
|
*/
|
||||||
public function setDisplayRoute($route)
|
public function setDisplayRoute($route)
|
||||||
{
|
{
|
||||||
|
$this->assertHasProcess();
|
||||||
|
|
||||||
$this->process->setDisplayRoute($route);
|
$this->process->setDisplayRoute($route);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -119,6 +127,8 @@ class ProcessBuilder implements ProcessBuilderInterface
|
||||||
*/
|
*/
|
||||||
public function setForwardRoute($route)
|
public function setForwardRoute($route)
|
||||||
{
|
{
|
||||||
|
$this->assertHasProcess();
|
||||||
|
|
||||||
$this->process->setForwardRoute($route);
|
$this->process->setForwardRoute($route);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -129,6 +139,8 @@ class ProcessBuilder implements ProcessBuilderInterface
|
||||||
*/
|
*/
|
||||||
public function setRedirect($redirect)
|
public function setRedirect($redirect)
|
||||||
{
|
{
|
||||||
|
$this->assertHasProcess();
|
||||||
|
|
||||||
$this->process->setRedirect($redirect);
|
$this->process->setRedirect($redirect);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -139,6 +151,8 @@ class ProcessBuilder implements ProcessBuilderInterface
|
||||||
*/
|
*/
|
||||||
public function validate(\Closure $validator)
|
public function validate(\Closure $validator)
|
||||||
{
|
{
|
||||||
|
$this->assertHasProcess();
|
||||||
|
|
||||||
$this->process->setValidator($validator);
|
$this->process->setValidator($validator);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -167,4 +181,16 @@ class ProcessBuilder implements ProcessBuilderInterface
|
||||||
|
|
||||||
return $this->steps[$alias];
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -172,17 +172,20 @@ class Coordinator implements CoordinatorInterface
|
||||||
*/
|
*/
|
||||||
protected function redirectToStepDisplayAction(ProcessInterface $process, StepInterface $step)
|
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()) {
|
if (null !== $route = $process->getDisplayRoute()) {
|
||||||
$url = $this->router->generate($route, array(
|
$url = $this->router->generate($route, array(
|
||||||
'stepName' => $step->getName()
|
'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);
|
return new RedirectResponse($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,7 +200,7 @@ class Coordinator implements CoordinatorInterface
|
||||||
{
|
{
|
||||||
$processScenario = $this->loadScenario($scenarioAlias);
|
$processScenario = $this->loadScenario($scenarioAlias);
|
||||||
|
|
||||||
$process = $this->builder->build($processScenario, $scenarioAlias);
|
$process = $this->builder->build($processScenario);
|
||||||
$process->setScenarioAlias($scenarioAlias);
|
$process->setScenarioAlias($scenarioAlias);
|
||||||
|
|
||||||
return $process;
|
return $process;
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,9 @@ class Process implements ProcessInterface
|
||||||
*/
|
*/
|
||||||
public function setSteps(array $steps)
|
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;
|
return $this->orderedSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function setOrderedSteps(array $orderedSteps)
|
|
||||||
{
|
|
||||||
$this->orderedSteps = $orderedSteps;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getStepByIndex($index)
|
public function getStepByIndex($index)
|
||||||
{
|
{
|
||||||
if (!isset($this->orderedSteps[$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];
|
return $this->orderedSteps[$index];
|
||||||
|
|
|
||||||
|
|
@ -57,13 +57,6 @@ interface ProcessInterface
|
||||||
*/
|
*/
|
||||||
function getOrderedSteps();
|
function getOrderedSteps();
|
||||||
|
|
||||||
/**
|
|
||||||
* Set ordered steps.
|
|
||||||
*
|
|
||||||
* @param array $steps
|
|
||||||
*/
|
|
||||||
function setOrderedSteps(array $steps);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get first process step.
|
* Get first process step.
|
||||||
*
|
*
|
||||||
|
|
@ -164,4 +157,18 @@ interface ProcessInterface
|
||||||
* @param string $route
|
* @param string $route
|
||||||
*/
|
*/
|
||||||
function setForwardRoute($route);
|
function setForwardRoute($route);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get step by index/order
|
||||||
|
*
|
||||||
|
* @return StepInterface
|
||||||
|
*/
|
||||||
|
function getStepByIndex($index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get step by name
|
||||||
|
*
|
||||||
|
* @return StepInterface
|
||||||
|
*/
|
||||||
|
function getStepByName($index);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue