1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer\Parser\FieldParser; |
4
|
|
|
|
5
|
|
|
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface; |
6
|
|
|
use Graze\CiffRenderer\Parser\FieldParserRegistry; |
7
|
|
|
use \SimpleXMLElement; |
8
|
|
|
|
9
|
|
|
abstract class AbstractFieldParser implements FieldParserInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var FieldParserRegistry |
13
|
|
|
*/ |
14
|
|
|
protected $fieldParserRegistry; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var SimpleXMLElement |
18
|
|
|
*/ |
19
|
|
|
protected $xmlHeader; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var SimpleXMLElement |
23
|
|
|
*/ |
24
|
|
|
protected $xmlField; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var float |
28
|
|
|
*/ |
29
|
|
|
protected $scale; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param FieldParserRegistry $fieldParserRegistry |
33
|
|
|
* @param SimpleXMLElement $xmlHeader |
34
|
|
|
* @param SimpleXMLElement $xmlField |
35
|
|
|
* @param float $scale |
36
|
|
|
*/ |
37
|
57 |
|
public function __construct( |
38
|
|
|
FieldParserRegistry $fieldParserRegistry, |
39
|
|
|
SimpleXMLElement $xmlHeader, |
40
|
|
|
SimpleXMLElement $xmlField, |
41
|
|
|
$scale |
42
|
|
|
) { |
43
|
57 |
|
$this->fieldParserRegistry = $fieldParserRegistry; |
44
|
57 |
|
$this->xmlHeader = $xmlHeader; |
45
|
57 |
|
$this->xmlField = $xmlField; |
46
|
57 |
|
$this->scale = $scale; |
47
|
57 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function getFieldType() |
53
|
|
|
{ |
54
|
|
|
return (string) $this->xmlField->FldType; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
6 |
|
public function getFieldName() |
61
|
|
|
{ |
62
|
6 |
|
return (string) $this->xmlField->attributes()->Name; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return int |
67
|
|
|
*/ |
68
|
6 |
|
public function getPositionX() |
69
|
|
|
{ |
70
|
6 |
|
return (int) ($this->xmlField->X * $this->scale); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return int |
75
|
|
|
*/ |
76
|
6 |
|
public function getPositionY() |
77
|
|
|
{ |
78
|
6 |
|
return (int) ($this->xmlField->Y * $this->scale); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return int |
83
|
|
|
*/ |
84
|
6 |
|
public function getWidth() |
85
|
|
|
{ |
86
|
6 |
|
return (int) ($this->xmlField->W * $this->scale); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return int |
91
|
|
|
*/ |
92
|
6 |
|
public function getHeight() |
93
|
|
|
{ |
94
|
6 |
|
return (int) ($this->xmlField->H * $this->scale); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
6 |
|
public function isDisplayed() |
101
|
|
|
{ |
102
|
6 |
|
return (string) $this->xmlField->Displayed != '0'; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param FieldParserRegistry $fieldParserRegistry |
107
|
|
|
* @param SimpleXMLElement $xmlHeader |
108
|
|
|
* @param SimpleXMLElement $xmlField |
109
|
|
|
* @param float $scale |
110
|
|
|
* @return FieldParserInterface |
111
|
|
|
*/ |
112
|
5 |
|
public static function factory( |
113
|
|
|
FieldParserRegistry $fieldParserRegistry, |
114
|
|
|
SimpleXMLElement $xmlHeader, |
115
|
|
|
SimpleXMLElement $xmlField, |
116
|
|
|
$scale |
117
|
|
|
) { |
118
|
5 |
|
return new static( |
119
|
5 |
|
$fieldParserRegistry, |
120
|
5 |
|
$xmlHeader, |
121
|
5 |
|
$xmlField, |
122
|
|
|
$scale |
123
|
5 |
|
); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: