From 18e6796726d73d7dc90ecdd16c181493941f5487 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 15 Dec 2016 10:13:00 +0100 Subject: REST API structure using Slim framework * REST API routes are handle by Slim. * Every API controller go through ApiMiddleware which handles security. * First service implemented `/info`, for tests purpose. --- application/api/exceptions/ApiException.php | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 application/api/exceptions/ApiException.php (limited to 'application/api/exceptions/ApiException.php') diff --git a/application/api/exceptions/ApiException.php b/application/api/exceptions/ApiException.php new file mode 100644 index 00000000..c8490e0c --- /dev/null +++ b/application/api/exceptions/ApiException.php @@ -0,0 +1,77 @@ +debug !== true) { + return $this->getMessage(); + } + return [ + 'message' => $this->getMessage(), + 'stacktrace' => get_class($this) .': '. $this->getTraceAsString() + ]; + } + + /** + * Build the Response object to return. + * + * @param int $code HTTP status. + * + * @return Response with status + body. + */ + protected function buildApiResponse($code) + { + $style = $this->debug ? JSON_PRETTY_PRINT : null; + return $this->response->withJson($this->getApiResponseBody(), $code, $style); + } + + /** + * @param Response $response + */ + public function setResponse($response) + { + $this->response = $response; + } + + /** + * @param bool $debug + */ + public function setDebug($debug) + { + $this->debug = $debug; + } +} -- cgit v1.2.3