2015-11-03 03:20:38 +01:00
|
|
|
<?php
|
2015-11-19 01:57:59 +01:00
|
|
|
class Response {
|
2018-11-22 20:00:40 +01:00
|
|
|
private static $response;
|
|
|
|
private static $responseException;
|
2015-11-03 03:20:38 +01:00
|
|
|
|
2018-12-24 01:44:59 +01:00
|
|
|
public static function respondError($errorMsg, $exception = null, $data = null) {
|
2018-11-22 20:00:40 +01:00
|
|
|
self::$response = array(
|
2015-11-03 03:20:38 +01:00
|
|
|
'status' => 'fail',
|
|
|
|
'message' => $errorMsg,
|
2018-12-24 01:44:59 +01:00
|
|
|
'data' => $data
|
2015-11-03 03:20:38 +01:00
|
|
|
);
|
2018-11-22 20:00:40 +01:00
|
|
|
self::$responseException = $exception;
|
2015-11-03 03:20:38 +01:00
|
|
|
|
|
|
|
$app = \Slim\Slim::getInstance();
|
2017-02-18 19:28:23 +01:00
|
|
|
$app->response->headers->set('Content-Type', 'application/json');
|
2018-11-22 20:00:40 +01:00
|
|
|
$app->response->setBody(json_encode(self::$response));
|
2017-02-18 19:28:23 +01:00
|
|
|
$app->response->finalize();
|
2015-11-03 03:20:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function respondSuccess($data = null) {
|
2018-11-22 20:00:40 +01:00
|
|
|
self::$response = array(
|
2015-11-03 03:20:38 +01:00
|
|
|
'status' => 'success',
|
|
|
|
'data' => $data
|
|
|
|
);
|
|
|
|
|
|
|
|
$app = \Slim\Slim::getInstance();
|
2017-02-18 19:28:23 +01:00
|
|
|
$app->response->headers->set('Content-Type', 'application/json');
|
2018-11-22 20:00:40 +01:00
|
|
|
$app->response->setBody(json_encode(self::$response));
|
2017-02-18 19:28:23 +01:00
|
|
|
$app->response->finalize();
|
2015-11-03 03:20:38 +01:00
|
|
|
}
|
2017-06-26 00:03:56 +02:00
|
|
|
|
|
|
|
public static function respond403() {
|
|
|
|
$app = \Slim\Slim::getInstance();
|
|
|
|
$app->response->setStatus(403);
|
|
|
|
$app->response->finalize();
|
|
|
|
}
|
2015-11-03 03:20:38 +01:00
|
|
|
}
|