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\SchemaReader; |
8
|
|
|
|
9
|
|
|
class ElementRef extends Item implements ElementSingle |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var ElementDef |
13
|
|
|
*/ |
14
|
|
|
protected $wrapped; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var int |
18
|
|
|
*/ |
19
|
|
|
protected $min = 1; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
protected $max = 1; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
protected $qualified = true; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
protected $nil = false; |
35
|
|
|
|
36
|
135 |
|
public function __construct(ElementDef $element) |
37
|
|
|
{ |
38
|
135 |
|
parent::__construct($element->getSchema(), $element->getName()); |
39
|
135 |
|
$this->wrapped = $element; |
40
|
135 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return ElementDef |
44
|
|
|
*/ |
45
|
|
|
public function getReferencedElement() |
46
|
|
|
{ |
47
|
|
|
return $this->wrapped; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \GoetasWebservices\XML\XSDReader\Schema\Type\Type|null |
52
|
|
|
*/ |
53
|
|
|
public function getType() |
54
|
|
|
{ |
55
|
|
|
return $this->wrapped->getType(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return int |
60
|
|
|
*/ |
61
|
|
|
public function getMin() |
62
|
|
|
{ |
63
|
|
|
return $this->min; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param int $min |
68
|
|
|
* |
69
|
|
|
* @return $this |
70
|
|
|
*/ |
71
|
135 |
|
public function setMin($min) |
72
|
|
|
{ |
73
|
135 |
|
$this->min = $min; |
74
|
|
|
|
75
|
135 |
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return int |
80
|
|
|
*/ |
81
|
|
|
public function getMax() |
82
|
|
|
{ |
83
|
|
|
return $this->max; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param int $max |
88
|
|
|
* |
89
|
|
|
* @return $this |
90
|
|
|
*/ |
91
|
135 |
|
public function setMax($max) |
92
|
|
|
{ |
93
|
135 |
|
$this->max = $max; |
94
|
|
|
|
95
|
135 |
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
|
|
public function isQualified() |
102
|
|
|
{ |
103
|
|
|
return $this->qualified; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param bool $qualified |
108
|
|
|
* |
109
|
|
|
* @return $this |
110
|
|
|
*/ |
111
|
|
|
public function setQualified($qualified) |
112
|
|
|
{ |
113
|
|
|
$this->qualified = is_bool($qualified) ? $qualified : (bool) $qualified; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
|
|
public function isNil() |
122
|
|
|
{ |
123
|
|
|
return $this->nil; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param bool $nil |
128
|
|
|
* |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
|
|
public function setNil($nil) |
132
|
|
|
{ |
133
|
|
|
$this->nil = is_bool($nil) ? $nil : (bool) $nil; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return ElementRef |
140
|
|
|
*/ |
141
|
135 |
|
public static function loadElementRef( |
142
|
|
|
ElementDef $referenced, |
143
|
|
|
DOMElement $node |
144
|
|
|
) { |
145
|
135 |
|
$ref = new self($referenced); |
146
|
135 |
|
$ref->setDoc(SchemaReader::getDocumentation($node)); |
147
|
|
|
|
148
|
135 |
|
SchemaReader::maybeSetMax($ref, $node); |
149
|
135 |
|
SchemaReader::maybeSetMin($ref, $node); |
150
|
135 |
|
if ($node->hasAttribute('nillable')) { |
151
|
|
|
$ref->setNil($node->getAttribute('nillable') == 'true'); |
152
|
|
|
} |
153
|
135 |
|
if ($node->hasAttribute('form')) { |
154
|
|
|
$ref->setQualified($node->getAttribute('form') == 'qualified'); |
155
|
|
|
} |
156
|
|
|
|
157
|
135 |
|
return $ref; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|