Эх сурвалжийг харах

feat: 去除xml渲染代码,改为html

runphp 1 сар өмнө
parent
commit
287aa43515
2 өөрчлөгдсөн 6 нэмэгдсэн , 45 устгасан
  1. 0 32
      src/Response/Xml.php
  2. 6 13
      src/functions.php

+ 0 - 32
src/Response/Xml.php

@@ -1,32 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace SixShop\Core\Response;
-
-class Xml extends \think\response\Xml
-{
-    protected function xmlEncode($data, string $root, string $item, $attr, string $id, string $encoding): string
-    {
-        if (is_array($attr)) {
-            $array = [];
-            foreach ($attr as $key => $value) {
-                $array[] = "$key=\"$value\"";
-            }
-            $attr = implode(' ', $array);
-        }
-
-        $attr = trim($attr);
-        $attr = empty($attr) ? '' : " $attr";
-        $xml = "<?xml version=\"1.0\" encoding=\"$encoding\"?>";
-        if ($this->options['xslt']) {
-            $xml .= '<?xml-stylesheet type="text/xsl" href="' . $this->options['xslt'] . '"?>';
-        }
-        $xml .= "<$root$attr>";
-        $xml .= $this->dataToXml($data, $item, $id);
-        $xml .= "</$root>";
-
-        return $xml;
-
-    }
-}

+ 6 - 13
src/functions.php

@@ -6,34 +6,27 @@ namespace SixShop\Core;
 
 use Random\RandomException;
 use SixShop\Core\Exception\LogicException;
-use SixShop\Core\Response\Xml;
 use SixShop\Core\Service\CoreService;
-use think\Container;
 use think\Paginator;
 use think\Response;
+use think\facade\View;
 
 /**
  * 返回成功数据
  */
-function success_response(mixed $data = [], string $status = 'ok', int $code = 200, string $msg = 'success', string $type = 'json', string $xslt = ''): Response
+function success_response(mixed $data = [], string $status = 'ok', int $code = 200, string $msg = 'success', string $type = 'json', string $template = ''): Response
 {
-    if ($xslt) {
-        $type = 'xml';
-    }
     $responseData = [
         'code' => $code,
         'status' => $status,
         'msg' => $msg,
         'data' => $data
     ];
-    if ($type == 'xml') {
-        /* @var Xml $response */
-        $response = Container::getInstance()->invokeClass(Xml::class, [$responseData, 200]);
-        $response = $response->options(['root_node' => 'root', 'xslt' => $xslt]);
-    } else {
-        $response = Response::create($responseData, $type);
+    if ($type == 'html') {
+        View::assign($responseData);
+        $responseData = View::fetch($template);
     }
-    return $response;
+    return Response::create($responseData, $type);
 }