XMLWriter.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. if (!defined('DATE_W3C')) {
  8. define('DATE_W3C', 'Y-m-d\TH:i:sP');
  9. }
  10. if (!defined('DEBUGMODE_ENABLED')) {
  11. define('DEBUGMODE_ENABLED', false);
  12. }
  13. /**
  14. * PHPExcel_Shared_XMLWriter
  15. *
  16. * Copyright (c) 2006 - 2015 PHPExcel
  17. *
  18. * This library is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU Lesser General Public
  20. * License as published by the Free Software Foundation; either
  21. * version 2.1 of the License, or (at your option) any later version.
  22. *
  23. * This library is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. * Lesser General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Lesser General Public
  29. * License along with this library; if not, write to the Free Software
  30. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  31. *
  32. * @category PHPExcel
  33. * @package PHPExcel_Shared
  34. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  35. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  36. * @version ##VERSION##, ##DATE##
  37. */
  38. class PHPExcel_Shared_XMLWriter extends XMLWriter
  39. {
  40. /** Temporary storage method */
  41. const STORAGE_MEMORY = 1;
  42. const STORAGE_DISK = 2;
  43. /**
  44. * Temporary filename
  45. *
  46. * @var string
  47. */
  48. private $tempFileName = '';
  49. /**
  50. * Create a new PHPExcel_Shared_XMLWriter instance
  51. *
  52. * @param int $pTemporaryStorage Temporary storage location
  53. * @param string $pTemporaryStorageFolder Temporary storage folder
  54. */
  55. public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = null)
  56. {
  57. // Open temporary storage
  58. if ($pTemporaryStorage == self::STORAGE_MEMORY) {
  59. $this->openMemory();
  60. } else {
  61. // Create temporary filename
  62. if ($pTemporaryStorageFolder === null) {
  63. $pTemporaryStorageFolder = PHPExcel_Shared_File::sys_get_temp_dir();
  64. }
  65. $this->tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
  66. // Open storage
  67. if ($this->openUri($this->tempFileName) === false) {
  68. // Fallback to memory...
  69. $this->openMemory();
  70. }
  71. }
  72. // Set default values
  73. if (DEBUGMODE_ENABLED) {
  74. $this->setIndent(true);
  75. }
  76. }
  77. /**
  78. * Destructor
  79. */
  80. public function __destruct()
  81. {
  82. // Unlink temporary files
  83. if ($this->tempFileName != '') {
  84. @unlink($this->tempFileName);
  85. }
  86. }
  87. /**
  88. * Get written data
  89. *
  90. * @return $data
  91. */
  92. public function getData()
  93. {
  94. if ($this->tempFileName == '') {
  95. return $this->outputMemory(true);
  96. } else {
  97. $this->flush();
  98. return file_get_contents($this->tempFileName);
  99. }
  100. }
  101. /**
  102. * Fallback method for writeRaw, introduced in PHP 5.2
  103. *
  104. * @param string $text
  105. * @return string
  106. */
  107. public function writeRawData($text)
  108. {
  109. if (is_array($text)) {
  110. $text = implode("\n", $text);
  111. }
  112. if (method_exists($this, 'writeRaw')) {
  113. return $this->writeRaw(htmlspecialchars($text));
  114. }
  115. return $this->text($text);
  116. }
  117. }