コード例 #1
0
ファイル: CSVResponse.php プロジェクト: phrest/api
 /**
  * @param Response $controllerResponse
  */
 public function __construct($controllerResponse)
 {
     if ($controllerResponse instanceof ResponseArray) {
         foreach ($controllerResponse->getResponses() as $response) {
             $this->records[] = $response->getData();
         }
     } elseif ($controllerResponse instanceof Response) {
         $this->records[] = $controllerResponse->getData();
     }
     parent::__construct();
 }
コード例 #2
0
ファイル: JSONResponse.php プロジェクト: spuy767/api
 public function __construct(Response $response)
 {
     parent::__construct();
     $this->setStatusCode($response->getStatusCode(), $response->getStatusMessage());
     $this->data = $response->getData();
     $this->meta = $response->getMeta();
     $this->messages = $response->getMessages();
 }
コード例 #3
0
ファイル: PhrestAPI.php プロジェクト: phrest/api
 /**
  * If the application throws an HTTPException, respond correctly (json etc.)
  * todo this was not working as the try catch blocks in controllers
  * was catching the exception before it would be handled, need
  * to come back to this
  */
 public function setExceptionHandler(DiInterface $di)
 {
     //return $this;
     set_exception_handler(function ($exception) use($di) {
         /** @var $exception Exception */
         // Handled exceptions
         if (is_a($exception, 'Phrest\\API\\Exceptions\\HandledException')) {
             $response = new Response();
             $response->setStatusCode($exception->getCode(), $exception->getMessage());
             $response->addMessage($exception->getMessage(), ResponseMessage::TYPE_WARNING);
             return (new JSONResponse($response))->send();
         } else {
             $response = new Response();
             $response->setStatusCode(500, 'Internal Server Error');
             $response->addMessage('Internal Server Error', ResponseMessage::TYPE_WARNING);
             (new JSONResponse($response))->send();
         }
         // Log the exception
         error_log($exception);
         error_log($exception->getTraceAsString());
         return true;
     });
 }