* Remove use exit for api.
This commit is contained in:
@@ -18,9 +18,9 @@ class entry extends baseEntry
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if($this->app->action == 'options') return $this->send(204);
|
||||
if($this->app->action == 'options') throw EndResponseException::create($this->send(204));
|
||||
|
||||
if(!isset($this->app->user) or $this->app->user->account == 'guest') $this->sendError(401, 'Unauthorized');
|
||||
if(!isset($this->app->user) or $this->app->user->account == 'guest') throw EndResponseException::create($this->sendError(401, 'Unauthorized'));
|
||||
|
||||
$this->dao = $this->loadModel('common')->dao;
|
||||
}
|
||||
@@ -199,7 +199,7 @@ class baseEntry
|
||||
* @param int $code
|
||||
* @param mixed $data
|
||||
* @access public
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
public function send($code, $data = '')
|
||||
{
|
||||
@@ -210,8 +210,7 @@ class baseEntry
|
||||
header("Content-type: application/json");
|
||||
header("HTTP/1.1 {$this->statusCode[$code]}");
|
||||
|
||||
if($data) echo json_encode($data, JSON_HEX_TAG);
|
||||
exit;
|
||||
return !empty($data) ? json_encode($data, JSON_HEX_TAG) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,14 +220,14 @@ class baseEntry
|
||||
* @param int $code
|
||||
* @param string $msg
|
||||
* @access public
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
public function sendError($code, $msg)
|
||||
{
|
||||
$response = new stdclass();
|
||||
$response->error = $msg;
|
||||
|
||||
$this->send($code, $response);
|
||||
return $this->send($code, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,14 +237,14 @@ class baseEntry
|
||||
* @param int $code
|
||||
* @param string $msg
|
||||
* @access public
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
public function sendSuccess($code, $msg)
|
||||
{
|
||||
$response = new stdclass();
|
||||
$response->message = $msg;
|
||||
|
||||
$this->send($code, $response);
|
||||
return $this->send($code, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,22 +252,22 @@ class baseEntry
|
||||
*
|
||||
* @param string message
|
||||
* @access public
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
public function send400($message = 'error')
|
||||
{
|
||||
$this->sendError(400, $message);
|
||||
return $this->sendError(400, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send 404 response.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
public function send404()
|
||||
{
|
||||
$this->sendError(404, '404 Not found');
|
||||
return $this->sendError(404, '404 Not found');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -673,7 +672,7 @@ class baseEntry
|
||||
* @param string $method
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return void
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetch($entry, $method, $params = array())
|
||||
{
|
||||
@@ -688,7 +687,7 @@ class baseEntry
|
||||
* Check the user has permission to access this method, if not, return 403.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @return void|string
|
||||
*/
|
||||
public function checkPriv()
|
||||
{
|
||||
@@ -696,7 +695,7 @@ class baseEntry
|
||||
$method = $this->app->getMethodName();
|
||||
if($module and $method and !$this->loadModel('common')->isOpenMethod($module, $method) and !commonModel::hasPriv($module, $method))
|
||||
{
|
||||
$this->send(403, array('error' => 'Access not allowed'));
|
||||
return $this->send(403, array('error' => 'Access not allowed'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user