1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Element; |
3
|
|
|
|
4
|
|
|
use DOMElement; |
5
|
|
|
use DOMXPath; |
6
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Item; |
7
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Schema; |
8
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReader; |
9
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReaderLoadAbstraction; |
10
|
|
|
|
11
|
|
|
class Element extends Item implements ElementItem, ElementSingle |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var int |
15
|
|
|
*/ |
16
|
|
|
protected $min = 1; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var int |
20
|
|
|
*/ |
21
|
|
|
protected $max = 1; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var bool |
25
|
|
|
*/ |
26
|
|
|
protected $qualified = false; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
protected $nil = false; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return int |
35
|
|
|
*/ |
36
|
6 |
|
public function getMin() |
37
|
|
|
{ |
38
|
6 |
|
return $this->min; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param int $min |
43
|
|
|
* |
44
|
|
|
* @return $this |
45
|
|
|
*/ |
46
|
135 |
|
public function setMin($min) |
47
|
|
|
{ |
48
|
135 |
|
$this->min = $min; |
49
|
135 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return int |
54
|
|
|
*/ |
55
|
12 |
|
public function getMax() |
56
|
|
|
{ |
57
|
12 |
|
return $this->max; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param int $max |
62
|
|
|
* |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
135 |
|
public function setMax($max) |
66
|
|
|
{ |
67
|
135 |
|
$this->max = $max; |
68
|
135 |
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
3 |
|
public function isQualified() |
75
|
|
|
{ |
76
|
3 |
|
return $this->qualified; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param bool $qualified |
81
|
|
|
* |
82
|
|
|
* @return $this |
83
|
|
|
*/ |
84
|
9 |
|
public function setQualified($qualified) |
85
|
|
|
{ |
86
|
9 |
|
$this->qualified = is_bool($qualified) ? $qualified : (boolean) $qualified; |
87
|
9 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
3 |
|
public function isNil() |
94
|
|
|
{ |
95
|
3 |
|
return $this->nil; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param bool $nil |
100
|
|
|
* |
101
|
|
|
* @return $this |
102
|
|
|
*/ |
103
|
9 |
|
public function setNil($nil) |
104
|
|
|
{ |
105
|
9 |
|
$this->nil = is_bool($nil) ? $nil : (boolean) $nil; |
106
|
9 |
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return Element |
111
|
|
|
*/ |
112
|
135 |
|
public static function loadElement( |
113
|
|
|
SchemaReaderLoadAbstraction $reader, |
114
|
|
|
Schema $schema, |
115
|
|
|
DOMElement $node |
116
|
|
|
) { |
117
|
135 |
|
$element = new Element($schema, $node->getAttribute("name")); |
118
|
135 |
|
$element->setDoc(SchemaReader::getDocumentation($node)); |
119
|
|
|
|
120
|
135 |
|
$reader->fillItem($element, $node); |
121
|
|
|
|
122
|
135 |
|
SchemaReader::maybeSetMax($element, $node); |
123
|
135 |
|
SchemaReader::maybeSetMin($element, $node); |
124
|
|
|
|
125
|
135 |
|
$xp = new \DOMXPath($node->ownerDocument); |
126
|
135 |
|
$xp->registerNamespace('xs', 'http://www.w3.org/2001/XMLSchema'); |
127
|
|
|
|
128
|
135 |
|
if ($xp->query('ancestor::xs:choice', $node)->length) { |
129
|
135 |
|
$element->setMin(0); |
130
|
45 |
|
} |
131
|
|
|
|
132
|
135 |
|
if ($node->hasAttribute("nillable")) { |
133
|
9 |
|
$element->setNil($node->getAttribute("nillable") == "true"); |
134
|
3 |
|
} |
135
|
135 |
|
if ($node->hasAttribute("form")) { |
136
|
9 |
|
$element->setQualified($node->getAttribute("form") == "qualified"); |
137
|
3 |
|
} |
138
|
135 |
|
return $element; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|