Blame view
sources/apps/contacts/lib/jsonresponse.php
2.01 KB
|
d1bafeea1
|
1 2 |
<?php /** |
|
6d9380f96
|
3 4 5 |
* @author Thomas Tanghus * @copyright 2013-2014 Thomas Tanghus (thomas@tanghus.net) * |
|
d1bafeea1
|
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Contacts;
use OCP\AppFramework\Http\JSONResponse as OriginalResponse,
OCP\AppFramework\Http;
/**
* A renderer for JSON calls
*/
class JSONResponse extends OriginalResponse {
public function __construct($params = array(), $statusCode = Http::STATUS_OK) {
parent::__construct(array(), $statusCode);
$this->data = $params;
}
/**
* Sets values in the data json array
* @param array|object $params an array or object which will be transformed
* to JSON
*/
public function setParams(array $params) {
$this->setData($params);
return $this;
}
public function setData($data) {
$this->data = $data;
return $this;
}
public function setStatus($status) {
parent::setStatus($status);
return $this;
}
/**
* in case we want to render an error message, also logs into the owncloud log
* @param string $message the error message
*/
public function setErrorMessage($message){
$this->error = true;
|
|
6d9380f96
|
52 |
$this->data = array('status' => 'error', 'data' => array('message' => $message));
|
|
d1bafeea1
|
53 54 |
return $this; } |
|
6d9380f96
|
55 |
public function bailOut($msg, $tracelevel = 1, $debuglevel = \OCP\Util::ERROR) {
|
|
d1bafeea1
|
56 |
if($msg instanceof \Exception) {
|
|
d1bafeea1
|
57 |
$this->setStatus($msg->getCode()); |
|
6d9380f96
|
58 |
$msg = $msg->getMessage(); |
|
d1bafeea1
|
59 60 61 62 |
} $this->setErrorMessage($msg); return $this->debug($msg, $tracelevel, $debuglevel); } |
|
6d9380f96
|
63 |
public function debug($msg, $tracelevel = 0, $debuglevel = \OCP\Util::DEBUG) {
|
|
d1bafeea1
|
64 65 66 67 68 |
if(!is_numeric($tracelevel)) {
return $this;
}
if(PHP_VERSION >= "5.4") {
|
|
6d9380f96
|
69 |
$call = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $tracelevel + 1); |
|
d1bafeea1
|
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
} else {
$call = debug_backtrace(false);
}
$call = $call[$tracelevel];
if($debuglevel !== false) {
\OCP\Util::writeLog('contacts',
$call['file'].'. Line: '.$call['line'].': '.$msg,
$debuglevel);
}
return $this;
}
}
|