From 776284e559f6ea0b7191833009f24e7be17aabe6 Mon Sep 17 00:00:00 2001 From: Vaidas Zilionis Date: Thu, 28 Dec 2017 12:15:04 +0200 Subject: [PATCH 1/3] replace private to protected. add missing methods --- Form/FormFlow.php | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 2a06869f..54f2b8d6 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -90,85 +90,85 @@ abstract class FormFlow implements FormFlowInterface { /** * @var RequestStack */ - private $requestStack; + protected $requestStack; /** * @var string|null Is only null if not yet initialized. */ - private $id = null; + protected $id = null; /** * @var string|null Is only null if not yet initialized. */ - private $instanceKey = null; + protected $instanceKey = null; /** * @var string|null Is only null if not yet initialized. */ - private $instanceId = null; + protected $instanceId = null; /** * @var string|null Is only null if not yet initialized. */ - private $formStepKey = null; + protected $formStepKey = null; /** * @var string|null Is only null if not yet initialized. */ - private $formTransitionKey = null; + protected $formTransitionKey = null; /** * @var string|null Is only null if not yet initialized. */ - private $validationGroupPrefix = null; + protected $validationGroupPrefix = null; /** * @var StepInterface[]|null Is only null if not yet initialized. */ - private $steps = null; + protected $steps = null; /** * @var int|null Is only null if not yet initialized. */ - private $stepCount = null; + protected $stepCount = null; /** * @var string[]|null Is only null if not yet initialized. */ - private $stepLabels = null; + protected $stepLabels = null; /** * @var mixed|null Is only null if not yet initialized. */ - private $formData = null; + protected $formData = null; /** * @var int|null Is only null if not yet initialized. */ - private $currentStepNumber = null; + protected $currentStepNumber = null; /** * @var FormInterface[] */ - private $stepForms = array(); + protected $stepForms = array(); /** * Options applied to forms of all steps. * @var array */ - private $genericFormOptions = array(); + protected $genericFormOptions = array(); /** * Flow was determined to be expired. * @var bool */ - private $expired = false; + protected $expired = false; /** * Instance ID was a newly generated ID. * @var bool */ - private $newInstance = false; + protected $newInstance = false; /** * {@inheritDoc} @@ -576,7 +576,7 @@ protected function determineCurrentStepNumber() { * @param int $stepNumber * @return int */ - private function ensureStepNumberRange($stepNumber) { + protected function ensureStepNumberRange($stepNumber) { return max(min($stepNumber, $this->getStepCount()), 1); } @@ -1094,4 +1094,12 @@ public function hasSkipStep($stepNumber) { return $this->isStepSkipped($stepNumber); } + public function isNewInstance() { + return $this->newInstance; + } + + public function isExpired() { + return $this->expired; + } + } From 973195a5c38361dffc7f453511ad80877b227357 Mon Sep 17 00:00:00 2001 From: Vaidas Zilionis Date: Thu, 28 Dec 2017 12:27:47 +0200 Subject: [PATCH 2/3] a small improvement to code quality --- Form/FormFlow.php | 64 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 54f2b8d6..051d5ab4 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -640,40 +640,46 @@ protected function determineInstanceId() { return $instanceId; } - protected function bindFlow() { - $request = $this->getRequest(); - $reset = false; - - if (!$this->allowDynamicStepNavigation && !$this->allowRedirectAfterSubmit && $request->isMethod('GET')) { - $reset = true; - } - - if ($this->getRequestedTransition() === self::TRANSITION_RESET) { - $reset = true; - } - - if (in_array($request->getMethod(), array('POST', 'PUT')) && $request->get($this->getFormStepKey()) !== null && !$this->dataManager->exists($this)) { - // flow is expired, drop posted data and reset - $request->request->replace(); - $reset = true; - $this->expired = true; + /** + * @return bool + */ + protected function isNeedToResetFlow() + { + $request = $this->getRequest(); + $reset = false; + + if (!$this->allowDynamicStepNavigation && !$this->allowRedirectAfterSubmit && $request->isMethod('GET')) { + $reset = true; + } + + if ($this->getRequestedTransition() === self::TRANSITION_RESET) { + $reset = true; + } + + if (in_array($request->getMethod(), array('POST', 'PUT')) && $request->get($this->getFormStepKey()) !== null && !$this->dataManager->exists($this)) { + // flow is expired, drop posted data and reset + $request->request->replace(); + $reset = true; + $this->expired = true; + + // Regenerate instance ID so resubmits of the form will continue to give error. Otherwise, submitting + // the new form, then backing up to the old form won't give the error. + $this->setInstanceId($this->determineInstanceId()); + } + + return $reset; + } - // Regenerate instance ID so resubmits of the form will continue to give error. Otherwise, submitting - // the new form, then backing up to the old form won't give the error. - $this->setInstanceId($this->determineInstanceId()); - } + protected function bindFlow() { + if ($this->isNeedToResetFlow()) { + $this->reset(); + return; + } - if (!$reset) { - $this->applyDataFromSavedSteps(); - } + $this->applyDataFromSavedSteps(); $requestedStepNumber = $this->determineCurrentStepNumber(); - if ($reset) { - $this->reset(); - return; - } - // ensure that the requested step fits the current progress if ($requestedStepNumber > $this->getFirstStepNumber()) { for ($step = $this->getFirstStepNumber(); $step < $requestedStepNumber; ++$step) { From 0f96df2ce749d224732ee8858b1e96524607062c Mon Sep 17 00:00:00 2001 From: Vaidas Zilionis Date: Thu, 28 Dec 2017 12:40:31 +0200 Subject: [PATCH 3/3] fix failing test --- Form/FormFlow.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 051d5ab4..6b7bdd26 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -671,14 +671,19 @@ protected function isNeedToResetFlow() } protected function bindFlow() { - if ($this->isNeedToResetFlow()) { - $this->reset(); - return; + + $reset = $this->isNeedToResetFlow(); + + if (!$reset) { + $this->applyDataFromSavedSteps(); } - $this->applyDataFromSavedSteps(); + $requestedStepNumber = $this->determineCurrentStepNumber(); - $requestedStepNumber = $this->determineCurrentStepNumber(); + if ($reset) { + $this->reset(); + return; + } // ensure that the requested step fits the current progress if ($requestedStepNumber > $this->getFirstStepNumber()) {