1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Attribute; |
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
|
|
|
|
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
|
|
|
|
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return static|null |
59
|
|
|
*/ |
60
|
|
|
public function getDefault() |
61
|
|
|
{ |
62
|
|
|
return $this->default; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param static $default |
67
|
|
|
* |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
|
|
public function setDefault($default) |
71
|
|
|
{ |
72
|
|
|
$this->default = $default; |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
1 |
|
public function isQualified() |
81
|
|
|
{ |
82
|
1 |
|
return $this->qualified; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param bool $qualified |
87
|
|
|
* |
88
|
|
|
* @return $this |
89
|
|
|
*/ |
90
|
1 |
|
public function setQualified($qualified) |
91
|
|
|
{ |
92
|
1 |
|
$this->qualified = $qualified; |
93
|
|
|
|
94
|
1 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
1 |
|
public function isNil() |
101
|
|
|
{ |
102
|
1 |
|
return $this->nil; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param bool $nil |
107
|
|
|
* |
108
|
|
|
* @return $this |
109
|
|
|
*/ |
110
|
1 |
|
public function setNil($nil) |
111
|
|
|
{ |
112
|
1 |
|
$this->nil = $nil; |
113
|
|
|
|
114
|
1 |
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
1 |
|
public function getUse() |
121
|
|
|
{ |
122
|
1 |
|
return $this->use; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param string $use |
127
|
|
|
* |
128
|
|
|
* @return $this |
129
|
|
|
*/ |
130
|
45 |
|
public function setUse($use) |
131
|
|
|
{ |
132
|
45 |
|
$this->use = $use; |
133
|
|
|
|
134
|
45 |
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return Attribute |
139
|
|
|
*/ |
140
|
45 |
|
public static function loadAttribute( |
141
|
|
|
SchemaReader $schemaReader, |
142
|
|
|
Schema $schema, |
143
|
|
|
DOMElement $node |
144
|
|
|
) { |
145
|
45 |
|
$attribute = new self($schema, $node->getAttribute('name')); |
146
|
45 |
|
$attribute->setDoc(SchemaReader::getDocumentation($node)); |
147
|
45 |
|
$schemaReader->fillItem($attribute, $node); |
148
|
|
|
|
149
|
45 |
|
if ($node->hasAttribute('nillable')) { |
150
|
1 |
|
$attribute->setNil($node->getAttribute('nillable') == 'true'); |
151
|
1 |
|
} |
152
|
45 |
|
if ($node->hasAttribute('form')) { |
153
|
1 |
|
$attribute->setQualified($node->getAttribute('form') == 'qualified'); |
154
|
1 |
|
} |
155
|
45 |
|
if ($node->hasAttribute('use')) { |
156
|
45 |
|
$attribute->setUse($node->getAttribute('use')); |
157
|
45 |
|
} |
158
|
|
|
|
159
|
45 |
|
return $attribute; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return AttributeItem |
164
|
|
|
*/ |
165
|
45 |
|
public static function getAttributeFromAttributeOrRef( |
166
|
|
|
SchemaReader $schemaReader, |
167
|
|
|
DOMElement $childNode, |
168
|
|
|
Schema $schema, |
169
|
|
|
DOMElement $node |
170
|
|
|
) { |
171
|
45 |
|
if ($childNode->hasAttribute('ref')) { |
172
|
|
|
/** |
173
|
|
|
* @var AttributeItem |
174
|
|
|
*/ |
175
|
45 |
|
$attribute = $schemaReader->findSomething('findAttribute', $schema, $node, $childNode->getAttribute('ref')); |
176
|
45 |
|
} else { |
177
|
|
|
/** |
178
|
|
|
* @var Attribute |
179
|
|
|
*/ |
180
|
45 |
|
$attribute = self::loadAttribute($schemaReader, $schema, $childNode); |
181
|
|
|
} |
182
|
|
|
|
183
|
45 |
|
return $attribute; |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|