Exemplo n.º 1
0
 /**
  * @param Request $request
  * @return \App\Installation\Result|array|void
  * @throws \LogicException
  */
 public function runWizard(Request $request)
 {
     if (!$this->initialized) {
         throw new \LogicException('Installator must be initialized before running');
     }
     $this->request = $request;
     $this->checkSessionStarted();
     $step = $request->param('id');
     $result = new Result();
     if (!$step) {
         $step = $this->firstStep->getName();
     }
     // Traverse all steps until current
     $stepObj = $this->firstStep;
     $lastStartedStep = $stepObj;
     while ($stepObj) {
         // Forbid executing not started steps.
         if (!$stepObj->isStarted()) {
             break;
         }
         $lastStartedStep = $stepObj;
         // Execute current step and stop.
         if ($step == $stepObj->getName()) {
             $result = $stepObj->execute(strtoupper($this->request->method), $this->request->getRequestData());
             if ($stepObj->getCompleted()) {
                 if ($nextStep = $stepObj->getNextStep()) {
                     $nextStep->start();
                 } else {
                     $result->setCompleted(true);
                 }
             }
             break;
         }
         // If invalid step is before current one, stop propagation, and ask user to fix it.
         if (!$stepObj->isValid()) {
             $result->setStep($stepObj);
             $result->redirectToStep();
             break;
         }
         $stepObj = $stepObj->getNextStep();
     }
     $this->stepsData['steps'][$stepObj->getName()]['current'] = true;
     $this->stepsData = ArraysHelper::arrayMergeRecursiveDistinct($this->stepsData, $stepObj->getViewData());
     $result->setViewData($this->stepsData);
     $result->setLastStartedStep($lastStartedStep);
     return $result;
 }