1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer\Parser\FieldParser; |
4
|
|
|
|
5
|
|
|
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface; |
6
|
|
|
use Graze\CiffRenderer\Parser\FieldParserRegistry; |
7
|
|
|
|
8
|
|
|
abstract class AbstractFieldParser implements FieldParserInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var FieldParserRegistry |
12
|
|
|
*/ |
13
|
|
|
protected $fieldParserRegistry; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var \SimpleXMLElement |
17
|
|
|
*/ |
18
|
|
|
protected $xmlField; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \SimpleXMLElement |
22
|
|
|
*/ |
23
|
|
|
protected $xmlHeader; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var float |
27
|
|
|
*/ |
28
|
|
|
protected $scale; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param FieldParserRegistry $fieldParserRegistry |
32
|
|
|
* @param \SimpleXMLElement $xmlField |
33
|
|
|
* @param \SimpleXMLElement $xmlHeader |
34
|
|
|
* @param float $scale |
35
|
|
|
*/ |
36
|
|
|
public function parse( |
37
|
|
|
FieldParserRegistry $fieldParserRegistry, |
38
|
|
|
\SimpleXMLElement $xmlField, |
39
|
|
|
\SimpleXMLElement $xmlHeader, |
40
|
|
|
$scale |
41
|
|
|
) { |
42
|
|
|
$this->fieldParserRegistry = $fieldParserRegistry; |
43
|
|
|
$this->xmlField = $xmlField; |
44
|
|
|
$this->xmlHeader = $xmlHeader; |
45
|
|
|
$this->scale = $scale; |
46
|
|
|
$this->fieldParserRegistry->addParser($this); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function getFieldName() |
53
|
|
|
{ |
54
|
|
|
return (string) $this->xmlField->attributes()->Name; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return int |
|
|
|
|
59
|
|
|
*/ |
60
|
|
|
public function getPositionX() |
61
|
|
|
{ |
62
|
|
|
return (int) $this->xmlField->X * $this->scale; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return int |
|
|
|
|
67
|
|
|
*/ |
68
|
|
|
public function getPositionY() |
69
|
|
|
{ |
70
|
|
|
return (int) $this->xmlField->Y * $this->scale; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return int |
|
|
|
|
75
|
|
|
*/ |
76
|
|
|
public function getWidth() |
77
|
|
|
{ |
78
|
|
|
return (int) $this->xmlField->W * $this->scale; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return int |
|
|
|
|
83
|
|
|
*/ |
84
|
|
|
public function getHeight() |
85
|
|
|
{ |
86
|
|
|
return (int) $this->xmlField->H * $this->scale; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
|
|
public function isDisplayed() |
93
|
|
|
{ |
94
|
|
|
return (string) $this->xmlField->Displayed != '0'; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return FieldParserInterface |
99
|
|
|
*/ |
100
|
|
|
public static function factory() |
101
|
|
|
{ |
102
|
|
|
return new static(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.