1 | <?php |
||
17 | class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper implements FileSystemWithRootFolderHelperInterface |
||
18 | { |
||
19 | const APP_NAME = 'Spout'; |
||
20 | |||
21 | const RELS_FOLDER_NAME = '_rels'; |
||
22 | const DOC_PROPS_FOLDER_NAME = 'docProps'; |
||
23 | const XL_FOLDER_NAME = 'xl'; |
||
24 | const WORKSHEETS_FOLDER_NAME = 'worksheets'; |
||
25 | |||
26 | const RELS_FILE_NAME = '.rels'; |
||
27 | const APP_XML_FILE_NAME = 'app.xml'; |
||
28 | const CORE_XML_FILE_NAME = 'core.xml'; |
||
29 | const CONTENT_TYPES_XML_FILE_NAME = '[Content_Types].xml'; |
||
30 | const WORKBOOK_XML_FILE_NAME = 'workbook.xml'; |
||
31 | const WORKBOOK_RELS_XML_FILE_NAME = 'workbook.xml.rels'; |
||
32 | const STYLES_XML_FILE_NAME = 'styles.xml'; |
||
33 | |||
34 | /** @var ZipHelper Helper to perform tasks with Zip archive */ |
||
35 | private $zipHelper; |
||
36 | |||
37 | /** @var string Path to the root folder inside the temp folder where the files to create the XLSX will be stored */ |
||
38 | private $rootFolder; |
||
39 | |||
40 | /** @var string Path to the "_rels" folder inside the root folder */ |
||
41 | private $relsFolder; |
||
42 | |||
43 | /** @var string Path to the "docProps" folder inside the root folder */ |
||
44 | private $docPropsFolder; |
||
45 | |||
46 | /** @var string Path to the "xl" folder inside the root folder */ |
||
47 | private $xlFolder; |
||
48 | |||
49 | /** @var string Path to the "_rels" folder inside the "xl" folder */ |
||
50 | private $xlRelsFolder; |
||
51 | |||
52 | /** @var string Path to the "worksheets" folder inside the "xl" folder */ |
||
53 | private $xlWorksheetsFolder; |
||
54 | |||
55 | /** |
||
56 | * @param string $baseFolderPath The path of the base folder where all the I/O can occur |
||
57 | * @param ZipHelper $zipHelper Helper to perform tasks with Zip archive |
||
58 | */ |
||
59 | 46 | public function __construct($baseFolderPath, $zipHelper) |
|
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | 36 | public function getRootFolder() |
|
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | 46 | public function getXlFolder() |
|
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | 46 | public function getXlWorksheetsFolder() |
|
88 | |||
89 | /** |
||
90 | * Creates all the folders needed to create a XLSX file, as well as the files that won't change. |
||
91 | * |
||
92 | * @return void |
||
93 | * @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the base folders |
||
94 | */ |
||
95 | 46 | public function createBaseFilesAndFolders() |
|
103 | |||
104 | /** |
||
105 | * Creates the folder that will be used as root |
||
106 | * |
||
107 | * @return FileSystemHelper |
||
108 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder |
||
109 | */ |
||
110 | 46 | private function createRootFolder() |
|
115 | |||
116 | /** |
||
117 | * Creates the "_rels" folder under the root folder as well as the ".rels" file in it |
||
118 | * |
||
119 | * @return FileSystemHelper |
||
120 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or the ".rels" file |
||
121 | */ |
||
122 | 46 | private function createRelsFolderAndFile() |
|
130 | |||
131 | /** |
||
132 | * Creates the ".rels" file under the "_rels" folder (under root) |
||
133 | * |
||
134 | * @return FileSystemHelper |
||
135 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the file |
||
136 | */ |
||
137 | 46 | private function createRelsFile() |
|
152 | |||
153 | /** |
||
154 | * Creates the "docProps" folder under the root folder as well as the "app.xml" and "core.xml" files in it |
||
155 | * |
||
156 | * @return FileSystemHelper |
||
157 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or one of the files |
||
158 | */ |
||
159 | 46 | private function createDocPropsFolderAndFiles() |
|
168 | |||
169 | /** |
||
170 | * Creates the "app.xml" file under the "docProps" folder |
||
171 | * |
||
172 | * @return FileSystemHelper |
||
173 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the file |
||
174 | */ |
||
175 | 46 | private function createAppXmlFile() |
|
190 | |||
191 | /** |
||
192 | * Creates the "core.xml" file under the "docProps" folder |
||
193 | * |
||
194 | * @return FileSystemHelper |
||
195 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the file |
||
196 | */ |
||
197 | 46 | private function createCoreXmlFile() |
|
213 | |||
214 | /** |
||
215 | * Creates the "xl" folder under the root folder as well as its subfolders |
||
216 | * |
||
217 | * @return FileSystemHelper |
||
218 | * @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the folders |
||
219 | */ |
||
220 | 46 | private function createXlFolderAndSubFolders() |
|
228 | |||
229 | /** |
||
230 | * Creates the "_rels" folder under the "xl" folder |
||
231 | * |
||
232 | * @return FileSystemHelper |
||
233 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder |
||
234 | */ |
||
235 | 46 | private function createXlRelsFolder() |
|
240 | |||
241 | /** |
||
242 | * Creates the "worksheets" folder under the "xl" folder |
||
243 | * |
||
244 | * @return FileSystemHelper |
||
245 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder |
||
246 | */ |
||
247 | 46 | private function createXlWorksheetsFolder() |
|
252 | |||
253 | /** |
||
254 | * Creates the "[Content_Types].xml" file under the root folder |
||
255 | * |
||
256 | * @param Worksheet[] $worksheets |
||
257 | * @return FileSystemHelper |
||
258 | */ |
||
259 | 36 | public function createContentTypesFile($worksheets) |
|
286 | |||
287 | /** |
||
288 | * Creates the "workbook.xml" file under the "xl" folder |
||
289 | * |
||
290 | * @param Worksheet[] $worksheets |
||
291 | * @return FileSystemHelper |
||
292 | */ |
||
293 | 36 | public function createWorkbookFile($worksheets) |
|
320 | |||
321 | /** |
||
322 | * Creates the "workbook.xml.res" file under the "xl/_res" folder |
||
323 | * |
||
324 | * @param Worksheet[] $worksheets |
||
325 | * @return FileSystemHelper |
||
326 | */ |
||
327 | 36 | public function createWorkbookRelsFile($worksheets) |
|
348 | |||
349 | /** |
||
350 | * Creates the "styles.xml" file under the "xl" folder |
||
351 | * |
||
352 | * @param StyleManager $styleManager |
||
353 | * @return FileSystemHelper |
||
354 | */ |
||
355 | 36 | public function createStylesFile($styleManager) |
|
362 | |||
363 | /** |
||
364 | * Zips the root folder and streams the contents of the zip into the given stream |
||
365 | * |
||
366 | * @param resource $streamPointer Pointer to the stream to copy the zip |
||
367 | * @return void |
||
368 | */ |
||
369 | 36 | public function zipRootFolderAndCopyToStream($streamPointer) |
|
388 | } |
||
389 |