opensupports/server/models/Response.php

38 lines
1.1 KiB
PHP
Raw Normal View History

<?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;
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(
'status' => 'fail',
'message' => $errorMsg,
2018-12-24 01:44:59 +01:00
'data' => $data
);
2018-11-22 20:00:40 +01:00
self::$responseException = $exception;
$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();
}
public static function respondSuccess($data = null) {
2018-11-22 20:00:40 +01:00
self::$response = array(
'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();
}
public static function respond403() {
$app = \Slim\Slim::getInstance();
$app->response->setStatus(403);
$app->response->finalize();
}
}