Example #1
0
 /**
  * Add a localized message to the response
  * @param string $translationKey translation key of the message
  * @param string $type type of the message
  * @param array $vars array with variables for the translator
  * @return null
  */
 private function addMessage($translationKey, $type, $vars)
 {
     $message = new Message($translationKey, $type, $vars);
     $this->response->addMessage($message);
 }
Example #2
0
 /**
  * Send the response to the client
  * @return null
  */
 private function sendResponse()
 {
     $this->eventManager->runEvent(self::EVENT_PRE_RESPONSE);
     $statusCode = $this->response->getStatusCode();
     $headers = $this->response->getHeaders();
     $this->sendHeaders($statusCode, $headers);
     if (!$this->response->willRedirect()) {
         $view = $this->response->getView();
         if (!empty($view)) {
             $view->render(false);
         }
     }
     $this->eventManager->runEvent(self::EVENT_POST_RESPONSE);
 }
Example #3
0
 /**
  * Invokes the wizard
  * @param zibo\core\Request $request The request
  * @param zibo\core\Response $response The response
  * @return null
  * @throws zibo\ZiboException when there are no steps in this wizard
  */
 public function invoke(Request $request, Response $response)
 {
     if (!$this->steps) {
         throw new ZiboException('This wizard does not contain any steps');
     }
     $this->request = $request;
     $this->response = $response;
     $this->currentStep = $this->getVariable(self::VARIABLE_CURRENT_STEP, $this->defaultStep);
     $step = $this->steps[$this->currentStep];
     $step->prepareForm();
     if ($this->isSubmitted()) {
         if ($this->getValue(self::BUTTON_CANCEL)) {
             $this->reset();
             if ($this->cancelUrl) {
                 $this->response->setRedirect($this->cancelUrl);
             } else {
                 $this->response->setRedirect($this->request->getBaseUrl());
             }
             return;
         }
         $nextStep = null;
         if ($this->getValue(self::BUTTON_PREVIOUS)) {
             $nextStep = $step->previous();
         } elseif ($this->getValue(self::BUTTON_NEXT)) {
             $nextStep = $step->next();
         } elseif ($this->getValue(self::BUTTON_FINISH)) {
             $nextStep = $step->finish();
         }
         if ($nextStep) {
             if (!$this->hasStep($nextStep)) {
                 throw new ZiboException('Cannot set the next step, invalid return value of step ' . $this->currentStep);
             }
             $this->setVariable(self::VARIABLE_CURRENT_STEP, $nextStep);
             $response->setRedirect($this->action);
         }
         if ($response->willRedirect()) {
             return;
         }
     }
     if (!$step->hasPrevious()) {
         $this->setIsDisabled(true, self::BUTTON_PREVIOUS);
     }
     if (!$step->hasNext()) {
         $this->setIsDisabled(true, self::BUTTON_NEXT);
     }
     if (!$step->hasFinish()) {
         $this->setIsDisabled(true, self::BUTTON_FINISH);
     }
     if (!$step->hasCancel()) {
         $this->setIsDisabled(true, self::BUTTON_CANCEL);
     }
     $view = $this->getView($step);
     if ($response->willRedirect()) {
         return;
     }
     $response->setView($view);
 }