From df5d57e13e81e307f08dc94db3950066a36806eb Mon Sep 17 00:00:00 2001 From: Rhilip Date: Fri, 8 Mar 2019 20:35:57 +0800 Subject: [PATCH] refactor(Helpers): Remove JsonHelper --- apps/config/http_base.php | 12 ------------ framework/Helpers/JsonHelper.php | 23 ----------------------- framework/Http/BaseResponse.php | 20 +++++++------------- framework/Http/Json.php | 21 --------------------- framework/Http/Jsonp.php | 29 ----------------------------- 5 files changed, 7 insertions(+), 98 deletions(-) delete mode 100644 framework/Helpers/JsonHelper.php delete mode 100644 framework/Http/Json.php delete mode 100644 framework/Http/Jsonp.php diff --git a/apps/config/http_base.php b/apps/config/http_base.php index b795014..b63e14e 100644 --- a/apps/config/http_base.php +++ b/apps/config/http_base.php @@ -52,18 +52,6 @@ 'class' => Rid\Http\Response::class, // 默认输出格式 'defaultFormat' => Rid\Http\Response::FORMAT_HTML, - // json - 'json' => [ - // 类路径 - 'class' => Rid\Http\Json::class, - ], - // jsonp - 'jsonp' => [ - // 类路径 - 'class' => Rid\Http\Jsonp::class, - // callback键名 - 'name' => 'callback', - ], // xml 'xml' => [ // 类路径 diff --git a/framework/Helpers/JsonHelper.php b/framework/Helpers/JsonHelper.php deleted file mode 100644 index 9660692..0000000 --- a/framework/Helpers/JsonHelper.php +++ /dev/null @@ -1,23 +0,0 @@ -format) { case self::FORMAT_JSON: - $content = $this->json->encode($content); + $content = json_encode($content, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); break; case self::FORMAT_JSONP: - $content = $this->jsonp->encode($content); - break; + { + $callback_key = app()->request->get('callback', 'callback'); + $content = json_encode($content, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + $content = $callback_key . '(' . $content . ')'; + break; + } case self::FORMAT_XML: $content = $this->xml->encode($content); break; diff --git a/framework/Http/Json.php b/framework/Http/Json.php deleted file mode 100644 index f6f45cc..0000000 --- a/framework/Http/Json.php +++ /dev/null @@ -1,21 +0,0 @@ -request->get($this->name); - if (is_null($callback)) { - return $jsonString; - } - return $callback . '(' . $jsonString . ')'; - } - -}