1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Akeneo\Component\SpreadsheetParser\Xlsx; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Spreadsheet relationships |
7
|
|
|
* |
8
|
|
|
* @author Antoine Guigan <[email protected]> |
9
|
|
|
* @copyright 2014 Akeneo SAS (http://www.akeneo.com) |
10
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
11
|
|
|
*/ |
12
|
|
|
class Relationships extends AbstractXMLResource |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $relationshipsPath; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
protected $workSheetPaths; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $stylePath; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $sharedStringPath; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Constructor |
41
|
|
|
* |
42
|
|
|
* @param string $path the path to the XML relationships file |
43
|
|
|
*/ |
44
|
|
|
public function __construct($path) |
45
|
|
|
{ |
46
|
|
|
parent::__construct($path); |
47
|
|
|
$xml = $this->getXMLReader(); |
48
|
|
|
|
49
|
|
|
while ($xml->read()) { |
50
|
|
|
if (\XMLReader::ELEMENT === $xml->nodeType && 'Relationship' === $xml->name) { |
51
|
|
|
|
52
|
|
|
$type = basename((string)$xml->getAttribute('Type')); |
53
|
|
|
$this->storeRelationShipByType($type, $xml->getAttribute('Id'), 'xl/' . $xml->getAttribute('Target')); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->closeXMLReader(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns the path of a worksheet file inside the xlsx file |
62
|
|
|
* |
63
|
|
|
* @param string $id |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getWorksheetPath($id) |
68
|
|
|
{ |
69
|
|
|
return $this->workSheetPaths[$id]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the path of the shared strings file inside the xlsx file |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getSharedStringsPath() |
78
|
|
|
{ |
79
|
|
|
return $this->sharedStringPath; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns the path of the styles XML file inside the xlsx file |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getStylesPath() |
88
|
|
|
{ |
89
|
|
|
return $this->stylePath; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* stores the relationShip into the right variable |
94
|
|
|
* |
95
|
|
|
* @param string $type |
96
|
|
|
* @param string $id |
97
|
|
|
* @param string $target |
98
|
|
|
*/ |
99
|
|
|
private function storeRelationShipByType($type, $id, $target) |
100
|
|
|
{ |
101
|
|
|
switch ($type) { |
102
|
|
|
case 'worksheet': |
103
|
|
|
$this->workSheetPaths[$id] = $target; |
104
|
|
|
break; |
105
|
|
|
case 'styles': |
106
|
|
|
$this->stylePath = $target; |
107
|
|
|
break; |
108
|
|
|
case 'sharedStrings': |
109
|
|
|
$this->sharedStringPath = $target; |
110
|
|
|
break; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|