1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Attribute; |
3
|
|
|
|
4
|
|
|
use DOMElement; |
5
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Item; |
6
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Schema; |
7
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReader; |
8
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReaderLoadAbstraction; |
9
|
|
|
|
10
|
|
|
class Attribute extends Item implements AttributeSingle |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var static|null |
14
|
|
|
*/ |
15
|
|
|
protected $fixed; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var static|null |
19
|
|
|
*/ |
20
|
|
|
protected $default; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
protected $qualified = true; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var bool |
29
|
|
|
*/ |
30
|
|
|
protected $nil = false; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $use = self::USE_OPTIONAL; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return static|null |
39
|
|
|
*/ |
40
|
|
|
public function getFixed() |
41
|
|
|
{ |
42
|
|
|
return $this->fixed; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param static $fixed |
47
|
|
|
* |
48
|
|
|
* @return $this |
49
|
|
|
*/ |
50
|
|
|
public function setFixed($fixed) |
51
|
|
|
{ |
52
|
|
|
$this->fixed = $fixed; |
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return static|null |
58
|
|
|
*/ |
59
|
|
|
public function getDefault() |
60
|
|
|
{ |
61
|
|
|
return $this->default; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param static $default |
66
|
|
|
* |
67
|
|
|
* @return $this |
68
|
|
|
*/ |
69
|
|
|
public function setDefault($default) |
70
|
|
|
{ |
71
|
|
|
$this->default = $default; |
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
3 |
|
public function isQualified() |
79
|
|
|
{ |
80
|
3 |
|
return $this->qualified; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param bool $qualified |
85
|
|
|
* |
86
|
|
|
* @return $this |
87
|
|
|
*/ |
88
|
3 |
|
public function setQualified($qualified) |
89
|
|
|
{ |
90
|
3 |
|
$this->qualified = $qualified; |
91
|
3 |
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
3 |
|
public function isNil() |
98
|
|
|
{ |
99
|
3 |
|
return $this->nil; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param bool $nil |
104
|
|
|
* |
105
|
|
|
* @return $this |
106
|
|
|
*/ |
107
|
3 |
|
public function setNil($nil) |
108
|
|
|
{ |
109
|
3 |
|
$this->nil = $nil; |
110
|
3 |
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
3 |
|
public function getUse() |
117
|
|
|
{ |
118
|
3 |
|
return $this->use; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param string $use |
123
|
|
|
* |
124
|
|
|
* @return $this |
125
|
|
|
*/ |
126
|
135 |
|
public function setUse($use) |
127
|
|
|
{ |
128
|
135 |
|
$this->use = $use; |
129
|
135 |
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return Attribute |
134
|
|
|
*/ |
135
|
135 |
|
public static function loadAttribute( |
136
|
|
|
SchemaReaderLoadAbstraction $schemaReader, |
137
|
|
|
Schema $schema, |
138
|
|
|
DOMElement $node |
139
|
|
|
) { |
140
|
135 |
|
$attribute = new Attribute($schema, $node->getAttribute("name")); |
141
|
135 |
|
$attribute->setDoc(SchemaReader::getDocumentation($node)); |
142
|
135 |
|
$schemaReader->fillItem($attribute, $node); |
143
|
|
|
|
144
|
135 |
|
if ($node->hasAttribute("nillable")) { |
145
|
3 |
|
$attribute->setNil($node->getAttribute("nillable") == "true"); |
146
|
1 |
|
} |
147
|
135 |
|
if ($node->hasAttribute("form")) { |
148
|
3 |
|
$attribute->setQualified($node->getAttribute("form") == "qualified"); |
149
|
1 |
|
} |
150
|
135 |
|
if ($node->hasAttribute("use")) { |
151
|
135 |
|
$attribute->setUse($node->getAttribute("use")); |
152
|
45 |
|
} |
153
|
135 |
|
return $attribute; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return AttributeItem |
158
|
|
|
*/ |
159
|
135 |
|
public static function getAttributeFromAttributeOrRef( |
160
|
|
|
SchemaReaderLoadAbstraction $schemaReader, |
161
|
|
|
DOMElement $childNode, |
162
|
|
|
Schema $schema, |
163
|
|
|
DOMElement $node |
164
|
|
|
) { |
165
|
135 |
|
if ($childNode->hasAttribute("ref")) { |
166
|
|
|
/** |
167
|
|
|
* @var AttributeItem $attribute |
168
|
|
|
*/ |
169
|
135 |
|
$attribute = $schemaReader->findSomething('findAttribute', $schema, $node, $childNode->getAttribute("ref")); |
170
|
45 |
|
} else { |
171
|
|
|
/** |
172
|
|
|
* @var Attribute $attribute |
173
|
|
|
*/ |
174
|
135 |
|
$attribute = Attribute::loadAttribute($schemaReader, $schema, $childNode); |
175
|
|
|
} |
176
|
|
|
|
177
|
135 |
|
return $attribute; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|