Xml.php 869 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\Core\Response;
  4. class Xml extends \think\response\Xml
  5. {
  6. protected function xmlEncode($data, string $root, string $item, $attr, string $id, string $encoding): string
  7. {
  8. if (is_array($attr)) {
  9. $array = [];
  10. foreach ($attr as $key => $value) {
  11. $array[] = "$key=\"$value\"";
  12. }
  13. $attr = implode(' ', $array);
  14. }
  15. $attr = trim($attr);
  16. $attr = empty($attr) ? '' : " $attr";
  17. $xml = "<?xml version=\"1.0\" encoding=\"$encoding\"?>";
  18. if ($this->options['xslt']) {
  19. $xml .= '<?xml-stylesheet type="text/xsl" href="' . $this->options['xslt'] . '"?>';
  20. }
  21. $xml .= "<$root$attr>";
  22. $xml .= $this->dataToXml($data, $item, $id);
  23. $xml .= "</$root>";
  24. return $xml;
  25. }
  26. }