/** * Handles Request Execution. * * @param mixed $request HttpRequest @see Native5/Route/HttpRequest * * @access public * @return void */ public function execute($request) { ob_start(); $logger = $GLOBALS['logger']; $this->_request = $request; $this->_response = new HttpResponse(); try { WebSessionManager::updateActiveSession(); foreach ($this->_preProcessors as $preProcessor) { $preProcessor->process($this->_request); } $functionToCall = $this->command->getFunction(); if (empty($functionToCall) === true) { $functionToCall = 'default'; } if (!is_callable(array(&$this, '_' . $functionToCall))) { $functionToCall = 'error'; } call_user_func(array(&$this, '_' . $functionToCall), $this->_request); foreach ($this->_postProcessors as $postProcessor) { $postProcessor->process($this->_response); } ob_end_clean(); if (empty($this->_response)) { $this->_response = new HttpResponse(); } if ($this->_response->getEncoding() == null) { $responseMode = $this->_request->getParam('mode'); if ($responseMode === 'ui') { $this->_response->setEncoding('html'); } else { if ($responseMode === 'data') { $this->_response->setEncoding('json'); } } } $this->_response->send(); } catch (ServiceException $se) { $this->_response = new HttpResponse(); $response->addHeader('HTTP/1.1 400 Bad Request'); $this->_response->send(); } catch (BadResponseException $bre) { $renderer = new TwigRenderer('500.html'); if ($renderer->exists()) { $this->_response = new HttpResponse('none', $renderer); } else { $this->_response = new HttpResponse(); } $response->addHeader('HTTP/1.1 500 Internal Server Error'); $this->_response->send(); } //end try }
/** * Handle Unauthenticated access. * * @access protected * @return void */ protected function _handleUnauthenticatedAccess() { header("HTTP/1.0 401 Unauthorized"); $renderer = new TwigRenderer(); $output = $renderer->render('unauth.tmpl', array()); $result = array("code" => "401", "message" => $output); echo parent::encodeData($result); exit; }