diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Json/Server/Error.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Json/Server/Error.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,198 @@ +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(); + } +} +