sInitialStepClass = $sInitialStepClass; $this->sInitialState = $sInitialState; $this->oSessionParameters = new SessionParameters(SetupUtils::SESSION_PARAMETERS_NAME); $this->oSessionParameters->LogParameters(); $this->aWizardSteps = $this->GetParameter('_steps', []); } /** * Pushes information about the current step onto the stack * @param array $aStepInfo Array('class' => , 'state' => ) */ protected function PushStep(array $aStepInfo): void { $this->aWizardSteps[] = $aStepInfo; $this->SetParameter('_steps', $this->aWizardSteps); } /** * Removes information about the previous step from the stack * @return array{'class': string, 'state': string} */ protected function PopStep(): array { $aStep = array_pop($this->aWizardSteps); $this->SetParameter('_steps', $this->aWizardSteps); return $aStep; } /** * Reads a "persistent" parameter from the wizard's context * @param string $sParamCode The code identifying this parameter * @param mixed $defaultValue The default value of the parameter in case it was not set */ public function GetParameter(string $sParamCode, mixed $defaultValue = ''): mixed { return $this->oSessionParameters->GetParameter($sParamCode, $defaultValue); } /** * @return array Allow to update config using {@see Config::UpdateFromParams()} * * @since 3.1.0 N°2013 */ public function GetParamForConfigArray(): array { /** @noinspection PhpUnnecessaryLocalVariableInspection */ $aParamValues = [ 'db_server' => $this->GetParameter('db_server', ''), 'db_user' => $this->GetParameter('db_user', ''), 'db_pwd' => $this->GetParameter('db_pwd', ''), 'db_name' => $this->GetParameter('db_name', ''), 'db_prefix' => $this->GetParameter('db_prefix', ''), 'db_tls_enabled' => $this->GetParameter('db_tls_enabled', false), 'db_tls_ca' => $this->GetParameter('db_tls_ca', ''), ]; return $aParamValues; } /** * Stores a "persistent" parameter in the wizard's context * * @param string $sParamCode The code identifying this parameter * @param mixed $value The value to store */ public function SetParameter(string $sParamCode, mixed $value): void { $this->oSessionParameters->SetParameter($sParamCode, $value); } /** * Stores the value of the page's parameter in a "persistent" parameter in the wizard's context * @param string $sParamCode The code identifying this parameter * @param mixed $defaultValue The default value for the parameter * @param string $sSanitizationFilter A 'sanitization' fitler. Default is 'raw_data', which means no filtering */ public function SaveParameter(string $sParamCode, mixed $defaultValue, string $sSanitizationFilter = 'raw_data'): void { $this->oSessionParameters->SetParameterFromParams($sParamCode, $defaultValue, $sSanitizationFilter); } /** * Stores the value of the page's parameter in a "persistent" parameter in the wizard's context * @param string $sParamCode The code identifying this parameter * @param mixed $defaultValue The default value for the parameter * @param string $sSanitizationFilter A 'sanitization' fitler. Default is 'raw_data', which means no filtering */ public function SavePostedParameter(string $sParamCode, mixed $defaultValue = '', string $sSanitizationFilter = 'raw_data'): void { $this->oSessionParameters->SetParameterFromPostedParams($sParamCode, $defaultValue, $sSanitizationFilter); } /** * Starts the wizard by displaying it in its initial state * * @throws \Exception */ public function Start(): void { $this->EraseParameters(); $sCurrentStepClass = $this->sInitialStepClass; $oStep = $this->GetWizardStep($sCurrentStepClass, $this->sInitialState); $this->DisplayStep($oStep); } /** * Progress towards the next step of the wizard * @throws Exception */ protected function Next(): void { $sCurrentStepClass = utils::ReadParam('_class', $this->sInitialStepClass); $sCurrentState = utils::ReadParam('_state', $this->sInitialState); $oStep = $this->GetWizardStep($sCurrentStepClass, $sCurrentState); if ($oStep->ValidateParams()) { $aPossibleSteps = $oStep->GetPossibleSteps(); if ($oStep->CanMoveBackward()) { $this->PushStep(['class' => $sCurrentStepClass, 'state' => $sCurrentState]); } $oWizardState = $oStep->UpdateWizardStateAndGetNextStep(true); // true => moving forward if (in_array($oWizardState->GetNextStep(), $aPossibleSteps)) { $oNextStep = $this->GetWizardStep($oWizardState->GetNextStep(), $oWizardState->GetState()); $this->DisplayStep($oNextStep); } else { throw new Exception("Internal error: Unexpected next step '{$oWizardState->GetNextStep()}'. The possible next steps are: ".implode(', ', $aPossibleSteps)); } } else { $this->DisplayStep($oStep); } } /** * Move one step back * * @throws \Exception */ protected function Back(): void { // let the current step save its parameters $sCurrentStepClass = utils::ReadParam('_class', $this->sInitialStepClass); $sCurrentState = utils::ReadParam('_state', $this->sInitialState); $oStep = $this->GetWizardStep($sCurrentStepClass, $sCurrentState); $oStep->UpdateWizardStateAndGetNextStep(false); // false => Moving backwards // Display the previous step $aCurrentStepInfo = $this->PopStep(); $oStep = $this->GetWizardStep($aCurrentStepInfo['class'], $aCurrentStepInfo['state']); $this->DisplayStep($oStep); } /** * Displays the specified 'step' of the wizard * * @param WizardStep $oStep The 'step' to display * * @throws \Exception */ protected function DisplayStep(WizardStep $oStep): void { SetupLog::Info("=== Setup screen: ".$oStep->GetTitle().' ('.get_class($oStep).')'); $oPage = new SetupPage($oStep->GetTitle()); $oPage->LinkScriptFromAppRoot('setup/setup.js'); $oPage->add('
"); $oStep->PostFormDisplay($oPage); $oPage->add(''); // The div may become visible in case of error // Hack to have the "Next >>" button, be the default button, since the first submit button in the form is the default one $oPage->add_ready_script( <<