PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Shared / XMLWriter.php

XMLWriter.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Shared/XMLWriter.php

110 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Shared;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
6
7 class XMLWriter extends \XMLWriter
8 {
9 public static bool $debugEnabled = false;
10
11 /** Temporary storage method */
12 const STORAGE_MEMORY = 1;
13 const STORAGE_DISK = 2;
14
15 /**
16 * Temporary filename.
17 */
18 private string $tempFileName = '';
19
20 /**
21 * Create a new XMLWriter instance.
22 *
23 * @param int $temporaryStorage Temporary storage location
24 * @param ?string $temporaryStorageFolder Temporary storage folder
25 */
26 public function __construct(int $temporaryStorage = self::STORAGE_MEMORY, ?string $temporaryStorageFolder = null)
27 {
28 // Open temporary storage
29 if ($temporaryStorage == self::STORAGE_MEMORY) {
30 $this->openMemory();
31 } else {
32 // Create temporary filename
33 if ($temporaryStorageFolder === null) {
34 $temporaryStorageFolder = File::sysGetTempDir();
35 }
36 $this->tempFileName = (string) @tempnam($temporaryStorageFolder, 'xml');
37
38 // Open storage
39 if (empty($this->tempFileName) || $this->openUri($this->tempFileName) === false) {
40 // Fallback to memory...
41 $this->openMemory();
42 if ($this->tempFileName != '') {
43 @unlink($this->tempFileName);
44 }
45 $this->tempFileName = '';
46 }
47 }
48
49 // Set default values
50 if (self::$debugEnabled) {
51 $this->setIndent(true);
52 }
53 }
54
55 /**
56 * Destructor.
57 */
58 public function __destruct()
59 {
60 // Unlink temporary files
61 // There is nothing reasonable to do if unlink fails.
62 if ($this->tempFileName != '') {
63 @unlink($this->tempFileName);
64 }
65 }
66
67 /**
68 * Unserialization is not allowed. This needs to be enforced
69 * in the class before Php8.6, but, with that release,
70 * this method is no longer needed and will not be executed.
71 *
72 * @see https://github.com/php/php-src/pull/21694
73 *
74 * @param mixed[] $data
75 */
76 public function __unserialize(array $data): void
77 {
78 $this->tempFileName = '';
79
80 throw new SpreadsheetException('Unserialize not permitted');
81 }
82
83 /**
84 * Get written data.
85 */
86 public function getData(): string
87 {
88 if ($this->tempFileName == '') {
89 return $this->outputMemory(true);
90 }
91 $this->flush();
92
93 return file_get_contents($this->tempFileName) ?: '';
94 }
95
96 /**
97 * Wrapper method for writeRaw.
98 *
99 * @param null|string|string[] $rawTextData
100 */
101 public function writeRawData($rawTextData): bool
102 {
103 if (is_array($rawTextData)) {
104 $rawTextData = implode("\n", $rawTextData);
105 }
106
107 return $this->text($rawTextData ?? '');
108 }
109 }
110