1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Type; |
3
|
|
|
|
4
|
|
|
use Closure; |
5
|
|
|
use DOMNode; |
6
|
|
|
use DOMElement; |
7
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReader; |
8
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Schema; |
9
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\SchemaItem; |
10
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Extension; |
11
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction; |
12
|
|
|
abstract class Type implements SchemaItem |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Schema |
16
|
|
|
*/ |
17
|
|
|
protected $schema; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string|null |
21
|
|
|
*/ |
22
|
|
|
protected $name; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
protected $abstract = false; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string|null |
31
|
|
|
*/ |
32
|
|
|
protected $doc; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @var Restriction|null |
37
|
|
|
*/ |
38
|
|
|
protected $restriction; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* |
42
|
|
|
* @var Extension|null |
43
|
|
|
*/ |
44
|
|
|
protected $extension; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string|null $name |
48
|
|
|
*/ |
49
|
135 |
|
public function __construct(Schema $schema, $name = null) |
50
|
|
|
{ |
51
|
135 |
|
$this->name = $name?:null; |
52
|
135 |
|
$this->schema = $schema; |
53
|
135 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string|null |
57
|
|
|
*/ |
58
|
135 |
|
public function getName() |
59
|
|
|
{ |
60
|
135 |
|
return $this->name; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $name |
65
|
|
|
* |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
|
|
public function setName($name) |
69
|
|
|
{ |
70
|
|
|
$this->name = $name; |
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string|null |
76
|
|
|
*/ |
77
|
|
|
public function getDoc() |
78
|
|
|
{ |
79
|
|
|
return $this->doc; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $doc |
84
|
|
|
* |
85
|
|
|
* @return $this |
86
|
|
|
*/ |
87
|
135 |
|
public function setDoc($doc) |
88
|
|
|
{ |
89
|
135 |
|
$this->doc = $doc; |
90
|
135 |
|
return $this; |
91
|
|
|
} |
92
|
|
|
/** |
93
|
|
|
* |
94
|
|
|
* @return Schema |
95
|
|
|
*/ |
96
|
135 |
|
public function getSchema() |
97
|
|
|
{ |
98
|
135 |
|
return $this->schema; |
99
|
|
|
} |
100
|
|
|
public function __toString() |
101
|
|
|
{ |
102
|
|
|
return strval($this->name); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
public function isAbstract() |
109
|
|
|
{ |
110
|
|
|
return $this->abstract; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param bool $abstract |
115
|
|
|
* |
116
|
|
|
* @return $this |
117
|
|
|
*/ |
118
|
135 |
|
public function setAbstract($abstract) |
119
|
|
|
{ |
120
|
135 |
|
$this->abstract = $abstract; |
121
|
135 |
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* |
126
|
|
|
* @return Restriction|Extension|null |
127
|
|
|
*/ |
128
|
|
|
public function getParent() |
129
|
|
|
{ |
130
|
|
|
return $this->restriction ? : $this->extension; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return Restriction|null |
135
|
|
|
*/ |
136
|
|
|
public function getRestriction() |
137
|
|
|
{ |
138
|
|
|
return $this->restriction; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return $this |
143
|
|
|
*/ |
144
|
135 |
|
public function setRestriction(Restriction $restriction) |
145
|
|
|
{ |
146
|
135 |
|
$this->restriction = $restriction; |
147
|
135 |
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return Extension|null |
152
|
|
|
*/ |
153
|
9 |
|
public function getExtension() |
154
|
|
|
{ |
155
|
9 |
|
return $this->extension; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return $this |
160
|
|
|
*/ |
161
|
135 |
|
public function setExtension(Extension $extension) |
162
|
|
|
{ |
163
|
135 |
|
$this->extension = $extension; |
164
|
135 |
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
135 |
|
public static function loadTypeWithCallbackOnChildNodes( |
168
|
|
|
SchemaReader $schemaReader, |
169
|
|
|
Schema $schema, |
170
|
|
|
DOMNode $node, |
171
|
|
|
Closure $callback |
172
|
|
|
) { |
173
|
135 |
|
foreach ($node->childNodes as $childNode) { |
174
|
135 |
|
static::loadTypeWithCallback( |
175
|
135 |
|
$schemaReader, |
176
|
135 |
|
$schema, |
177
|
135 |
|
$childNode, |
178
|
90 |
|
$callback |
179
|
45 |
|
); |
180
|
45 |
|
} |
181
|
135 |
|
} |
182
|
|
|
|
183
|
135 |
|
public static function loadTypeWithCallback( |
184
|
|
|
SchemaReader $schemaReader, |
185
|
|
|
Schema $schema, |
186
|
|
|
DOMNode $childNode, |
187
|
|
|
Closure $callback |
188
|
|
|
) { |
189
|
135 |
|
if (! ($childNode instanceof DOMElement)) { |
190
|
135 |
|
return; |
191
|
|
|
} |
192
|
|
|
$methods = [ |
193
|
135 |
|
'complexType' => 'loadComplexType', |
194
|
45 |
|
'simpleType' => 'loadSimpleType', |
195
|
45 |
|
]; |
196
|
|
|
|
197
|
135 |
|
$func = $schemaReader->maybeCallMethod( |
198
|
135 |
|
$methods, |
199
|
135 |
|
$childNode->localName, |
200
|
135 |
|
$childNode, |
201
|
135 |
|
$schema, |
202
|
135 |
|
$childNode, |
203
|
90 |
|
$callback |
204
|
45 |
|
); |
205
|
|
|
|
206
|
135 |
|
if ($func instanceof Closure) { |
207
|
135 |
|
call_user_func($func); |
208
|
45 |
|
} |
209
|
135 |
|
} |
210
|
|
|
} |
211
|
|
|
|