1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Element; |
4
|
|
|
|
5
|
|
|
use DOMElement; |
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
|
2 |
|
public function getMin() |
37
|
|
|
{ |
38
|
2 |
|
return $this->min; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param int $min |
43
|
|
|
* |
44
|
|
|
* @return $this |
45
|
|
|
*/ |
46
|
45 |
|
public function setMin($min) |
47
|
|
|
{ |
48
|
45 |
|
$this->min = $min; |
49
|
|
|
|
50
|
45 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return int |
55
|
|
|
*/ |
56
|
4 |
|
public function getMax() |
57
|
|
|
{ |
58
|
4 |
|
return $this->max; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param int $max |
63
|
|
|
* |
64
|
|
|
* @return $this |
65
|
|
|
*/ |
66
|
45 |
|
public function setMax($max) |
67
|
|
|
{ |
68
|
45 |
|
$this->max = $max; |
69
|
|
|
|
70
|
45 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
1 |
|
public function isQualified() |
77
|
|
|
{ |
78
|
1 |
|
return $this->qualified; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param bool $qualified |
83
|
|
|
* |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
3 |
|
public function setQualified($qualified) |
87
|
|
|
{ |
88
|
3 |
|
$this->qualified = is_bool($qualified) ? $qualified : (bool) $qualified; |
89
|
|
|
|
90
|
3 |
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
1 |
|
public function isNil() |
97
|
|
|
{ |
98
|
1 |
|
return $this->nil; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param bool $nil |
103
|
|
|
* |
104
|
|
|
* @return $this |
105
|
|
|
*/ |
106
|
3 |
|
public function setNil($nil) |
107
|
|
|
{ |
108
|
3 |
|
$this->nil = is_bool($nil) ? $nil : (bool) $nil; |
109
|
|
|
|
110
|
3 |
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return Element |
115
|
|
|
*/ |
116
|
45 |
|
public static function loadElement( |
117
|
|
|
SchemaReaderLoadAbstraction $reader, |
118
|
|
|
Schema $schema, |
119
|
|
|
DOMElement $node |
120
|
|
|
) { |
121
|
45 |
|
$element = new self($schema, $node->getAttribute('name')); |
122
|
45 |
|
$element->setDoc(SchemaReader::getDocumentation($node)); |
123
|
|
|
|
124
|
45 |
|
$reader->fillItem($element, $node); |
125
|
|
|
|
126
|
45 |
|
SchemaReader::maybeSetMax($element, $node); |
127
|
45 |
|
SchemaReader::maybeSetMin($element, $node); |
128
|
|
|
|
129
|
45 |
|
$xp = new \DOMXPath($node->ownerDocument); |
130
|
45 |
|
$xp->registerNamespace('xs', 'http://www.w3.org/2001/XMLSchema'); |
131
|
|
|
|
132
|
45 |
|
if ($xp->query('ancestor::xs:choice', $node)->length) { |
133
|
45 |
|
$element->setMin(0); |
134
|
45 |
|
} |
135
|
|
|
|
136
|
45 |
|
if ($node->hasAttribute('nillable')) { |
137
|
3 |
|
$element->setNil($node->getAttribute('nillable') == 'true'); |
138
|
3 |
|
} |
139
|
45 |
|
if ($node->hasAttribute('form')) { |
140
|
3 |
|
$element->setQualified($node->getAttribute('form') == 'qualified'); |
141
|
3 |
|
} |
142
|
|
|
|
143
|
45 |
|
return $element; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|