|
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 \SimpleXMLElement |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $xmlField; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var \SimpleXMLElement |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $xmlHeader; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var float |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $scale; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var FieldParserRegistry |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $fieldParserRegistry; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param \SimpleXMLElement $xmlField |
|
32
|
|
|
*/ |
|
33
|
|
|
public function setXmlField(\SimpleXMLElement $xmlField) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->xmlField = $xmlField; |
|
36
|
1 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param \SimpleXMLElement $xmlHeader |
|
40
|
|
|
*/ |
|
41
|
|
|
public function setXmlHeader(\SimpleXMLElement $xmlHeader) |
|
42
|
1 |
|
{ |
|
43
|
1 |
|
$this->xmlHeader = $xmlHeader; |
|
44
|
1 |
|
} |
|
45
|
1 |
|
|
|
46
|
1 |
|
/** |
|
47
|
1 |
|
* @param float $scale |
|
48
|
|
|
*/ |
|
49
|
|
|
public function setScale($scale) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->scale = $scale; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param FieldParserRegistry $fieldParserRegistry |
|
56
|
|
|
*/ |
|
57
|
|
|
public function setFieldParserRegistry(FieldParserRegistry $fieldParserRegistry) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->fieldParserRegistry = $fieldParserRegistry; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getFieldName() |
|
66
|
|
|
{ |
|
67
|
|
|
return (string) $this->xmlField->attributes()->Name; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return int |
|
|
|
|
|
|
72
|
|
|
*/ |
|
73
|
|
|
public function getPositionX() |
|
74
|
|
|
{ |
|
75
|
|
|
return (int) $this->xmlField->X * $this->scale; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return int |
|
|
|
|
|
|
80
|
|
|
*/ |
|
81
|
|
|
public function getPositionY() |
|
82
|
|
|
{ |
|
83
|
|
|
return (int) $this->xmlField->Y * $this->scale; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return int |
|
|
|
|
|
|
88
|
|
|
*/ |
|
89
|
|
|
public function getWidth() |
|
90
|
|
|
{ |
|
91
|
|
|
return (int) $this->xmlField->W * $this->scale; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return int |
|
|
|
|
|
|
96
|
|
|
*/ |
|
97
|
|
|
public function getHeight() |
|
98
|
|
|
{ |
|
99
|
|
|
return (int) $this->xmlField->H * $this->scale; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return bool |
|
104
|
|
|
*/ |
|
105
|
|
|
public function isDisplayed() |
|
106
|
|
|
{ |
|
107
|
|
|
return (string) $this->xmlField->Displayed != '0'; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return FieldParserInterface |
|
112
|
|
|
*/ |
|
113
|
|
|
public static function factory() |
|
114
|
|
|
{ |
|
115
|
|
|
return new static(); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.