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