Exemple #1
0
 public function sendResponse(IResponse $response)
 {
     if ($this->tidy->isEnabled() && $response instanceof TextResponse && $response->getSource() instanceof ITemplate) {
         $response = new TidyResponse($response, $this->tidy);
     }
     parent::sendResponse($response);
 }
 /**
  * @param Application $application
  * @param IResponse $response
  */
 public function process(Application $application, IResponse $response)
 {
     if ($response instanceof JsonResponse) {
         $response->setPostProcessor([$this, 'decorate']);
         $response->setContentType("text/html; charset=utf-8");
     }
 }
 /**
  * @return array|\stdClass
  */
 public function getPayload()
 {
     if (!$this->appResponse instanceof JsonResponse) {
         throw new \RuntimeException("Unexpected response");
     }
     return $this->appResponse->getPayload();
 }
Exemple #4
0
 /**
  * @return Nette\Application\IResponse
  */
 public function run(Application\Request $request)
 {
     try {
         // STARTUP
         $this->request = $request;
         $this->payload = new \stdClass();
         $this->setParent($this->getParent(), $request->getPresenterName());
         if (!$this->httpResponse->isSent()) {
             $this->httpResponse->addHeader('Vary', 'X-Requested-With');
         }
         $this->initGlobalParameters();
         $this->checkRequirements($this->getReflection());
         $this->startup();
         if (!$this->startupCheck) {
             $class = $this->getReflection()->getMethod('startup')->getDeclaringClass()->getName();
             throw new Nette\InvalidStateException("Method {$class}::startup() or its descendant doesn't call parent::startup().");
         }
         // calls $this->action<Action>()
         $this->tryCall($this->formatActionMethod($this->action), $this->params);
         // autoload components
         foreach ($this->globalParams as $id => $foo) {
             $this->getComponent($id, FALSE);
         }
         if ($this->autoCanonicalize) {
             $this->canonicalize();
         }
         if ($this->httpRequest->isMethod('head')) {
             $this->terminate();
         }
         // SIGNAL HANDLING
         // calls $this->handle<Signal>()
         $this->processSignal();
         // RENDERING VIEW
         $this->beforeRender();
         // calls $this->render<View>()
         $this->tryCall($this->formatRenderMethod($this->view), $this->params);
         $this->afterRender();
         // save component tree persistent state
         $this->saveGlobalState();
         if ($this->isAjax()) {
             $this->payload->state = $this->getGlobalState();
         }
         // finish template rendering
         $this->sendTemplate();
     } catch (Application\AbortException $e) {
         // continue with shutting down
         if ($this->isAjax()) {
             try {
                 $hasPayload = (array) $this->payload;
                 unset($hasPayload['state']);
                 if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
                     $this->snippetMode = TRUE;
                     $this->response->send($this->httpRequest, $this->httpResponse);
                     $this->sendPayload();
                 } elseif (!$this->response && $hasPayload) {
                     // back compatibility for use terminate() instead of sendPayload()
                     $this->sendPayload();
                 }
             } catch (Application\AbortException $e) {
             }
         }
         if ($this->hasFlashSession()) {
             $this->getFlashSession()->setExpiration($this->response instanceof Responses\RedirectResponse ? '+ 30 seconds' : '+ 3 seconds');
         }
         // SHUTDOWN
         $this->onShutdown($this, $this->response);
         $this->shutdown($this->response);
         return $this->response;
     }
 }
Exemple #5
0
 public function sendResponse(\Nette\Application\IResponse $response)
 {
     if ($response instanceof \Nette\Application\Responses\JsonResponse) {
         $response->send($this->getHttpRequest(), $this->getHttpResponse());
     } else {
         parent::sendResponse($response);
     }
 }