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 $xmlField; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var SimpleXMLElement |
23
|
|
|
*/ |
24
|
|
|
protected $xmlHeader; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var float |
28
|
|
|
*/ |
29
|
|
|
protected $scale; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param FieldParserRegistry $fieldParserRegistry |
33
|
|
|
* @param SimpleXMLElement $xmlField |
34
|
|
|
* @param SimpleXMLElement $xmlHeader |
35
|
|
|
* @param float $scale |
36
|
|
|
*/ |
37
|
49 |
|
public function parse( |
38
|
|
|
FieldParserRegistry $fieldParserRegistry, |
39
|
|
|
SimpleXMLElement $xmlField, |
40
|
|
|
SimpleXMLElement $xmlHeader, |
41
|
|
|
$scale |
42
|
|
|
) { |
43
|
49 |
|
$this->fieldParserRegistry = $fieldParserRegistry; |
44
|
49 |
|
$this->xmlField = $xmlField; |
45
|
49 |
|
$this->xmlHeader = $xmlHeader; |
46
|
49 |
|
$this->scale = $scale; |
47
|
49 |
|
$this->fieldParserRegistry->addParser($this); |
48
|
49 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getFieldType() |
54
|
|
|
{ |
55
|
|
|
return (string) $this->xmlField->FldType; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
6 |
|
public function getFieldName() |
62
|
|
|
{ |
63
|
6 |
|
return (string) $this->xmlField->attributes()->Name; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return int |
68
|
|
|
*/ |
69
|
6 |
|
public function getPositionX() |
70
|
|
|
{ |
71
|
6 |
|
return (int) ($this->xmlField->X * $this->scale); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return int |
76
|
|
|
*/ |
77
|
6 |
|
public function getPositionY() |
78
|
|
|
{ |
79
|
6 |
|
return (int) ($this->xmlField->Y * $this->scale); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return int |
84
|
|
|
*/ |
85
|
6 |
|
public function getWidth() |
86
|
|
|
{ |
87
|
6 |
|
return (int) ($this->xmlField->W * $this->scale); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return int |
92
|
|
|
*/ |
93
|
6 |
|
public function getHeight() |
94
|
|
|
{ |
95
|
6 |
|
return (int) ($this->xmlField->H * $this->scale); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
6 |
|
public function isDisplayed() |
102
|
|
|
{ |
103
|
6 |
|
return (string) $this->xmlField->Displayed != '0'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return FieldParserInterface |
108
|
|
|
*/ |
109
|
5 |
|
public static function factory() |
110
|
|
|
{ |
111
|
5 |
|
return new static(); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: