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 | 46 | public function __construct($filePath, $entityFactory) |
|
48 | |||
49 | /** |
||
50 | * @return string The path of the shared string XML file |
||
51 | */ |
||
52 | 39 | public function getSharedStringsXMLFilePath() |
|
66 | |||
67 | /** |
||
68 | * @return bool Whether the XLSX file contains a shared string XML file |
||
69 | */ |
||
70 | 40 | public function hasSharedStringsXMLFile() |
|
76 | |||
77 | /** |
||
78 | * @return string|null The path of the styles XML file |
||
79 | */ |
||
80 | 38 | public function getStylesXMLFilePath() |
|
94 | |||
95 | /** |
||
96 | * Reads the workbook.xml.rels and extracts the filename associated to the different types. |
||
97 | * It caches the result so that the file is read only once. |
||
98 | * |
||
99 | * @throws \Box\Spout\Common\Exception\IOException If workbook.xml.rels can't be read |
||
100 | * @return array |
||
101 | */ |
||
102 | 46 | private function getWorkbookRelationships() |
|
120 | |||
121 | /** |
||
122 | * Extracts and store the data of the current workbook relationship. |
||
123 | * |
||
124 | * @param XMLReader $xmlReader |
||
125 | * @return void |
||
126 | */ |
||
127 | 46 | private function processWorkbookRelationship($xmlReader) |
|
136 | } |
||
137 |