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