1 | <?php |
||
13 | class WorkbookRelationshipsManager |
||
14 | { |
||
15 | const BASE_PATH = 'xl/'; |
||
16 | |||
17 | /** Path of workbook relationships XML file inside the XLSX file */ |
||
18 | const WORKBOOK_RELS_XML_FILE_PATH = 'xl/_rels/workbook.xml.rels'; |
||
19 | |||
20 | /** Relationships types */ |
||
21 | const RELATIONSHIP_TYPE_SHARED_STRINGS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings'; |
||
22 | const RELATIONSHIP_TYPE_STYLES = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles'; |
||
23 | const RELATIONSHIP_TYPE_WORKSHEET = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet'; |
||
24 | |||
25 | /** Nodes and attributes used to find relevant information in the workbook relationships XML file */ |
||
26 | const XML_NODE_RELATIONSHIP = 'Relationship'; |
||
27 | const XML_ATTRIBUTE_TYPE = 'Type'; |
||
28 | const XML_ATTRIBUTE_TARGET = 'Target'; |
||
29 | |||
30 | /** @var string Path of the XLSX file being read */ |
||
31 | private $filePath; |
||
32 | |||
33 | /** @var InternalEntityFactory Factory to create entities */ |
||
34 | private $entityFactory; |
||
35 | |||
36 | /** @var array Cache of the already read workbook relationships: [TYPE] => [FILE_NAME] */ |
||
37 | private $cachedWorkbookRelationships; |
||
38 | |||
39 | /** |
||
40 | * @param string $filePath Path of the XLSX file being read |
||
41 | * @param InternalEntityFactory $entityFactory Factory to create entities |
||
42 | */ |
||
43 | 47 | public function __construct($filePath, $entityFactory) |
|
48 | |||
49 | /** |
||
50 | * @return string The path of the shared string XML file |
||
51 | */ |
||
52 | 40 | public function getSharedStringsXMLFilePath() |
|
66 | |||
67 | /** |
||
68 | * @return bool Whether the XLSX file contains a shared string XML file |
||
69 | */ |
||
70 | 41 | public function hasSharedStringsXMLFile() |
|
76 | |||
77 | /** |
||
78 | * @return bool Whether the XLSX file contains a styles XML file |
||
79 | */ |
||
80 | 39 | public function hasStylesXMLFile() |
|
86 | |||
87 | /** |
||
88 | * @return string The path of the styles XML file |
||
89 | */ |
||
90 | 38 | public function getStylesXMLFilePath() |
|
104 | |||
105 | /** |
||
106 | * Reads the workbook.xml.rels and extracts the filename associated to the different types. |
||
107 | * It caches the result so that the file is read only once. |
||
108 | * |
||
109 | * @throws \Box\Spout\Common\Exception\IOException If workbook.xml.rels can't be read |
||
110 | * @return array |
||
111 | */ |
||
112 | 47 | private function getWorkbookRelationships() |
|
130 | |||
131 | /** |
||
132 | * Extracts and store the data of the current workbook relationship. |
||
133 | * |
||
134 | * @param XMLReader $xmlReader |
||
135 | * @return void |
||
136 | */ |
||
137 | 47 | private function processWorkbookRelationship($xmlReader) |
|
146 | } |
||
147 |