1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace Spaghetti\XLSXParser; |
4
|
|
|
|
5
|
|
|
use XMLReader; |
6
|
|
|
|
7
|
|
|
use function basename; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @internal |
11
|
|
|
*/ |
12
|
|
|
final class Relationships extends AbstractXMLResource |
13
|
|
|
{ |
14
|
|
|
private const WORKSHEET = 'worksheet'; |
15
|
|
|
private const STYLES = 'styles'; |
16
|
|
|
private const SHARED_STRINGS = 'sharedStrings'; |
17
|
|
|
private const RELATIONSHIP = 'Relationship'; |
18
|
|
|
private const TARGET = 'Target'; |
19
|
|
|
private const TYPE = 'Type'; |
20
|
|
|
private const ID = 'Id'; |
21
|
|
|
|
22
|
|
|
private array $workSheetPaths = []; |
23
|
|
|
private string $sharedStringPath = ''; |
24
|
|
|
private string $stylePath = ''; |
25
|
|
|
|
26
|
|
|
public function __construct(string $path) |
27
|
|
|
{ |
28
|
|
|
parent::__construct(path: $path); |
29
|
|
|
$xml = $this->getXMLReader(); |
30
|
|
|
|
31
|
|
|
while ($xml->read()) { |
32
|
|
|
if (XMLReader::ELEMENT === $xml->nodeType && self::RELATIONSHIP === $xml->name) { |
33
|
|
|
$target = 'xl/' . $xml->getAttribute(name: self::TARGET); |
34
|
|
|
|
35
|
|
|
match (basename(path: (string) $xml->getAttribute(name: self::TYPE))) { |
36
|
|
|
self::WORKSHEET => $this->workSheetPaths[$xml->getAttribute(name: self::ID)] = $target, |
37
|
|
|
self::STYLES => $this->stylePath = $target, |
38
|
|
|
self::SHARED_STRINGS => $this->sharedStringPath = $target, |
39
|
|
|
default => null, |
40
|
|
|
}; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$this->closeXMLReader(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getWorksheetPath(string $rId): string |
48
|
|
|
{ |
49
|
|
|
return $this->workSheetPaths[$rId]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getSharedStringsPath(): string |
53
|
|
|
{ |
54
|
|
|
return $this->sharedStringPath; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getStylesPath(): string |
58
|
|
|
{ |
59
|
|
|
return $this->stylePath; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|