setMessage($message) ->setCode($code) ->setData($data); } /** * Set error code * * @param int $code * @return Zend_Json_Server_Error */ public function setCode($code) { if (!is_scalar($code)) { return $this; } $code = (int) $code; if (in_array($code, $this->_allowedCodes)) { $this->_code = $code; } elseif (in_array($code, range(-32099, -32000))) { $this->_code = $code; } return $this; } /** * Get error code * * @return int|null */ public function getCode() { return $this->_code; } /** * Set error message * * @param string $message * @return Zend_Json_Server_Error */ public function setMessage($message) { if (!is_scalar($message)) { return $this; } $this->_message = (string) $message; return $this; } /** * Get error message * * @return string */ public function getMessage() { return $this->_message; } /** * Set error data * * @param mixed $data * @return Zend_Json_Server_Error */ public function setData($data) { $this->_data = $data; return $this; } /** * Get error data * * @return mixed */ public function getData() { return $this->_data; } /** * Cast error to array * * @return array */ public function toArray() { return array( 'code' => $this->getCode(), 'message' => $this->getMessage(), 'data' => $this->getData(), ); } /** * Cast error to JSON * * @return string */ public function toJson() { #require_once 'Zend/Json.php'; return Zend_Json::encode($this->toArray()); } /** * Cast to string (JSON) * * @return string */ public function __toString() { return $this->toJson(); } }