|
|
@@ -44,14 +44,24 @@ class Response{
|
|
|
}
|
|
|
|
|
|
//=======================================================
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @ctag Response::header($key, $value);
|
|
|
+ *
|
|
|
+ */
|
|
|
public static function header($key, $value){
|
|
|
$istance = self::getInstance();
|
|
|
$istance->_headers[$key] = $value;
|
|
|
return $istance;
|
|
|
}
|
|
|
|
|
|
- public static function body_prepend($body = null){
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @ctag Response::bodyPrepend($value);
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public static function bodyPrepend($body = null){
|
|
|
$instance = self::getInstance();
|
|
|
if (null !== $body) {
|
|
|
$instance->_body = (string) $body . $instance->_body;
|
|
|
@@ -60,6 +70,11 @@ class Response{
|
|
|
return $instance;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @ctag Response::body($value);
|
|
|
+ *
|
|
|
+ */
|
|
|
public static function body($body = null){
|
|
|
$instance = self::getInstance();
|
|
|
if (null !== $body) {
|
|
|
@@ -69,7 +84,12 @@ class Response{
|
|
|
return $instance;
|
|
|
}
|
|
|
|
|
|
- public static function body_append($body = null){
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @ctag Response::bodyAppend($value);
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public static function bodyAppend($body = null){
|
|
|
$instance = self::getInstance();
|
|
|
if (null !== $body) {
|
|
|
$instance->_body .= (string) $body;
|
|
|
@@ -78,34 +98,45 @@ class Response{
|
|
|
return $instance;
|
|
|
}
|
|
|
|
|
|
- private function send_headers(){
|
|
|
+ private function sendHeaders(){
|
|
|
foreach ($this->_headers as $key => $value) {
|
|
|
header($key .': '. $value, false);
|
|
|
}
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- private function send_body(){
|
|
|
+ private function sendBody(){
|
|
|
echo (string) $this->_body;
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @ctag Response::bodySend();
|
|
|
+ *
|
|
|
+ */
|
|
|
public static function send(){
|
|
|
$instance = self::getInstance();
|
|
|
- $instance->send_headers();
|
|
|
- $instance->send_body();
|
|
|
+ $instance->sendHeaders();
|
|
|
+ $instance->sendBody();
|
|
|
return $instance;
|
|
|
}
|
|
|
|
|
|
- public static function json($object, $jsonp_prefix = null){
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @ctag Response::json($object);
|
|
|
+ * @ctag Response::json($object, $prefix);
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public static function json($object, $jsonPrefix = null){
|
|
|
$instance = self::getInstance();
|
|
|
|
|
|
$instance->body('');
|
|
|
|
|
|
$json = json_encode($object);
|
|
|
- if (null !== $jsonp_prefix) {
|
|
|
+ if (null !== $jsonPrefix) {
|
|
|
$instance->header('Content-Type', 'text/javascript');
|
|
|
- $instance->body("$jsonp_prefix($json);");
|
|
|
+ $instance->body("$jsonPrefix($json);");
|
|
|
} else {
|
|
|
$instance->header('Content-Type', 'application/json');
|
|
|
$instance->body($json);
|
|
|
@@ -113,6 +144,12 @@ class Response{
|
|
|
return $instance;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @ctag Response::redirect($url);
|
|
|
+ * @ctag Response::redirect($url, $code);
|
|
|
+ *
|
|
|
+ */
|
|
|
public static function redirect($url, $code = 302){
|
|
|
$instance = self::getInstance();
|
|
|
|
|
|
@@ -123,6 +160,11 @@ class Response{
|
|
|
$instance->send();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @ctag Response::back();
|
|
|
+ *
|
|
|
+ */
|
|
|
public static function back(){
|
|
|
$instance = self::getInstance();
|
|
|
|
|
|
@@ -132,7 +174,7 @@ class Response{
|
|
|
$instance->send();
|
|
|
}
|
|
|
|
|
|
- function done(){
|
|
|
+ public function done(){
|
|
|
die;
|
|
|
}
|
|
|
}
|