1 | <?php |
||
14 | class WorkbookRelationshipsManager |
||
15 | { |
||
16 | const BASE_PATH = 'xl/'; |
||
17 | |||
18 | /** Path of workbook relationships XML file inside the XLSX file */ |
||
19 | const WORKBOOK_RELS_XML_FILE_PATH = 'xl/_rels/workbook.xml.rels'; |
||
20 | |||
21 | /** Relationships types */ |
||
22 | const RELATIONSHIP_TYPE_SHARED_STRINGS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings'; |
||
23 | const RELATIONSHIP_TYPE_STYLES = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles'; |
||
24 | const RELATIONSHIP_TYPE_WORKSHEET = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet'; |
||
25 | |||
26 | /** Nodes and attributes used to find relevant information in the workbook relationships XML file */ |
||
27 | const XML_NODE_RELATIONSHIP = 'Relationship'; |
||
28 | const XML_ATTRIBUTE_TYPE = 'Type'; |
||
29 | const XML_ATTRIBUTE_TARGET = 'Target'; |
||
30 | |||
31 | /** @var string Path of the XLSX file being read */ |
||
32 | private $filePath; |
||
33 | |||
34 | /** @var EntityFactory Factory to create entities */ |
||
35 | private $entityFactory; |
||
36 | |||
37 | /** @var array Cache of the already read workbook relationships: [TYPE] => [FILE_NAME] */ |
||
38 | private $cachedWorkbookRelationships; |
||
39 | |||
40 | /** |
||
41 | * @param string $filePath Path of the XLSX file being read |
||
42 | * @param EntityFactory $entityFactory Factory to create entities |
||
43 | */ |
||
44 | 46 | public function __construct($filePath, $entityFactory) |
|
49 | |||
50 | /** |
||
51 | * @return string The path of the shared string XML file |
||
52 | */ |
||
53 | 39 | public function getSharedStringsXMLFilePath() |
|
67 | |||
68 | /** |
||
69 | * @return bool Whether the XLSX file contains a shared string XML file |
||
70 | */ |
||
71 | 40 | public function hasSharedStringsXMLFile() |
|
77 | |||
78 | /** |
||
79 | * @return string|null The path of the styles XML file |
||
80 | */ |
||
81 | 38 | public function getStylesXMLFilePath() |
|
95 | |||
96 | /** |
||
97 | * Reads the workbook.xml.rels and extracts the filename associated to the different types. |
||
98 | * It caches the result so that the file is read only once. |
||
99 | * |
||
100 | * @throws \Box\Spout\Common\Exception\IOException If workbook.xml.rels can't be read |
||
101 | * @return array |
||
102 | */ |
||
103 | 46 | private function getWorkbookRelationships() |
|
121 | |||
122 | /** |
||
123 | * Extracts and store the data of the current workbook relationship. |
||
124 | * |
||
125 | * @param XMLReader $xmlReader |
||
126 | * @return void |
||
127 | */ |
||
128 | 46 | private function processWorkbookRelationship($xmlReader) |
|
137 | } |
||
138 |