示例#1
0
文件: Api.php 项目: AyeAyeApi/Api
 /**
  * Process the request, get a response and return it.
  *
  * Exceptions thrown in most places will be handled here.
  * Currently there's no nice way to handle exceptions in Response::respond
  *
  * @return Response
  * @SuppressWarnings(PHPMD.ShortMethodName)
  */
 public function go()
 {
     $response = $this->getResponse();
     try {
         $request = $this->getRequest();
         $response->setWriterFactory($this->getWriterFactory());
         $response->setRequest($request);
         $response->setBodyData($this->getRouter()->processRequest($this->getRequest(), $this->controller));
         $response->setStatus($this->controller->getStatus());
     } catch (AyeAyeException $e) {
         $this->log(LogLevel::INFO, $e->getPublicMessage());
         $this->log(LogLevel::ERROR, $e->getMessage(), ['exception' => $e]);
         $response->setBodyData($e->getPublicMessage());
         $response->setStatus(new Status($e->getCode()));
     } catch (\Exception $e) {
         $status = new Status(500);
         $this->log(LogLevel::CRITICAL, $e->getMessage(), ['exception' => $e]);
         $response->setBodyData($status->getMessage());
         $response->setStatus($status);
     }
     // Ultimate fail safe
     try {
         $response->prepareResponse();
     } catch (\Exception $e) {
         $this->log(LogLevel::CRITICAL, $e->getMessage(), ['exception' => $e]);
         return $this->createFailSafeResponse();
     }
     return $response;
 }
示例#2
0
 /**
  * Get the status of the controller.
  *
  * This is a simple wrapper function.
  *
  * @return Status
  */
 public function getStatus()
 {
     return $this->controller->getStatus();
 }