1 | <?php |
||
12 | class SharedStringsManager |
||
13 | { |
||
14 | const SHARED_STRINGS_FILE_NAME = 'sharedStrings.xml'; |
||
15 | |||
16 | const SHARED_STRINGS_XML_FILE_FIRST_PART_HEADER = <<<'EOD' |
||
17 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
||
18 | <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" |
||
19 | EOD; |
||
20 | |||
21 | /** |
||
22 | * This number must be really big so that the no generated file will have more strings than that. |
||
23 | * If the strings number goes above, characters will be overwritten in an unwanted way and will corrupt the file. |
||
24 | */ |
||
25 | const DEFAULT_STRINGS_COUNT_PART = 'count="9999999999999" uniqueCount="9999999999999"'; |
||
26 | |||
27 | /** @var resource Pointer to the sharedStrings.xml file */ |
||
28 | protected $sharedStringsFilePointer; |
||
29 | |||
30 | /** @var int Number of shared strings already written */ |
||
31 | protected $numSharedStrings = 0; |
||
32 | |||
33 | /** @var Escaper\XLSX Strings escaper */ |
||
34 | protected $stringsEscaper; |
||
35 | |||
36 | /** |
||
37 | * @param string $xlFolder Path to the "xl" folder |
||
38 | * @param Escaper\XLSX $stringsEscaper Strings escaper |
||
39 | */ |
||
40 | 43 | public function __construct($xlFolder, $stringsEscaper) |
|
53 | |||
54 | /** |
||
55 | * Checks if the book has been created. Throws an exception if not created yet. |
||
56 | * |
||
57 | * @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing |
||
58 | * @return void |
||
59 | */ |
||
60 | 43 | protected function throwIfSharedStringsFilePointerIsNotAvailable() |
|
66 | |||
67 | /** |
||
68 | * Writes the given string into the sharedStrings.xml file. |
||
69 | * Starting and ending whitespaces are preserved. |
||
70 | * |
||
71 | * @param string $string |
||
72 | * @return int ID of the written shared string |
||
73 | */ |
||
74 | 3 | public function writeString($string) |
|
82 | |||
83 | /** |
||
84 | * Finishes writing the data in the sharedStrings.xml file and closes the file. |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | 39 | public function close() |
|
106 | } |
||
107 |