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