Exemplo n.º 1
0
 public static function createController($controllerName, Request $request, Pixie $pixie, $isSubRequest = false)
 {
     if (!$controllerName || $controllerName == 'Default') {
         $className = $request->param('namespace', $pixie->app_namespace) . 'Rest\\NoneController';
     } else {
         $className = $request->param('namespace', $pixie->app_namespace) . 'Rest\\Controller\\' . $controllerName;
     }
     if (!class_exists($className)) {
         if (!in_array($controllerName, $pixie->restService->getExcludedModels()) && class_exists($pixie->app_namespace . 'Model\\' . $controllerName)) {
             $className = $request->param('namespace', $pixie->app_namespace) . 'Rest\\Controller';
         } else {
             throw new NotFoundException();
         }
     }
     $controller = $pixie->controller($className);
     $controller->request = $request;
     $controller->setIsSubRequest($isSubRequest);
     // Inject model into the controller.
     if (!$controller->getModelName()) {
         $controller->setModelName($controllerName);
     }
     return $controller;
 }
Exemplo n.º 2
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;
 }