1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer\Parser; |
4
|
|
|
|
5
|
|
|
use Graze\CiffRenderer\Parser\FieldSorter; |
6
|
|
|
use Graze\CiffRenderer\Parser\FieldParser\FieldParserFactory; |
7
|
|
|
|
8
|
|
|
class ParserDocument |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var FieldSorter |
12
|
|
|
*/ |
13
|
|
|
private $fieldSorter; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var FieldParserFactory |
17
|
|
|
*/ |
18
|
|
|
private $fieldParserFactory; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var FieldParserRegistry |
22
|
|
|
*/ |
23
|
|
|
private $fieldParserRegistry; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \SimpleXMLElement |
27
|
|
|
*/ |
28
|
|
|
private $xml; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param FieldSorter $fieldSorter |
32
|
|
|
* @param FieldParserFactory $fieldParserFactory |
33
|
|
|
* @param FieldParserRegistry $fieldParserRegistry |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
FieldSorter $fieldSorter, |
37
|
|
|
FieldParserFactory $fieldParserFactory, |
38
|
|
|
FieldParserRegistry $fieldParserRegistry |
39
|
|
|
) { |
40
|
|
|
$this->fieldSorter = $fieldSorter; |
41
|
|
|
$this->fieldParserFactory = $fieldParserFactory; |
42
|
|
|
$this->fieldParserRegistry = $fieldParserRegistry; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param \SimpleXMLElement $xml |
47
|
|
|
*/ |
48
|
|
|
public function parse(\SimpleXMLElement $xml) |
49
|
|
|
{ |
50
|
|
|
$this->xml = $xml; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return ParserInterface[] |
55
|
|
|
*/ |
56
|
|
|
public function getFieldParsers() |
57
|
|
|
{ |
58
|
|
|
$subImage = (array) $this->xml->SubImage; |
59
|
|
|
$fields = $this->fieldSorter->sort($subImage['Field']); |
60
|
|
|
$parsers = []; |
61
|
|
|
foreach ($fields as $field) { |
62
|
|
|
$parser = $this->fieldParserFactory->getFieldParser($field); |
63
|
|
|
$parser->parse($this->fieldParserRegistry, $field, $this->xml->Header, $this->getScale()); |
64
|
|
|
$parsers[] = $parser; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $parsers; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return float |
72
|
|
|
*/ |
73
|
|
|
public function getWidth() |
74
|
|
|
{ |
75
|
|
|
return (float) $this->xml->SubImage->SubHeader->ImageWidth * $this->getScale(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return float |
80
|
|
|
*/ |
81
|
|
|
public function getHeight() |
82
|
|
|
{ |
83
|
|
|
return (float) $this->xml->SubImage->SubHeader->ImageHeight * $this->getScale(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return float |
88
|
|
|
*/ |
89
|
|
|
public function getScale() |
90
|
|
|
{ |
91
|
|
|
return (float) $this->xml->SubImage->SubHeader->XRes; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return ParserDocument |
96
|
|
|
*/ |
97
|
|
|
public static function factory() |
98
|
|
|
{ |
99
|
|
|
return new static( |
100
|
|
|
new FieldSorter(), |
101
|
|
|
new FieldParserFactory(), |
102
|
|
|
new FieldParserRegistry() |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|