1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader; |
3
|
|
|
|
4
|
|
|
use Closure; |
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use DOMNode; |
8
|
|
|
use DOMNodeList; |
9
|
|
|
use GoetasWebservices\XML\XSDReader\Exception\IOException; |
10
|
|
|
use GoetasWebservices\XML\XSDReader\Exception\TypeException; |
11
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Attribute\Attribute; |
12
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeDef; |
13
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem; |
14
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Attribute\Group as AttributeGroup; |
15
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\Element; |
16
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementContainer; |
17
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef; |
18
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementItem; |
19
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementRef; |
20
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\Group; |
21
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\GroupRef; |
22
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\InterfaceSetMinMax; |
23
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Exception\TypeNotFoundException; |
24
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Base; |
25
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Extension; |
26
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction; |
27
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Item; |
28
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Schema; |
29
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\SchemaItem; |
30
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\BaseComplexType; |
31
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType; |
32
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexTypeSimpleContent; |
33
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType; |
34
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\Type; |
35
|
|
|
use GoetasWebservices\XML\XSDReader\Utils\UrlUtils; |
36
|
|
|
use RuntimeException; |
37
|
|
|
|
38
|
|
|
abstract class SchemaReaderCallbackAbstraction extends AbstractSchemaReader |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @param mixed[][] $methods |
42
|
|
|
* |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
135 |
|
protected function maybeCallCallableWithArgs( |
46
|
|
|
DOMElement $childNode, |
47
|
|
|
array $commonMethods = [], |
48
|
|
|
array $methods = [], |
49
|
|
|
array $commonArguments = [] |
50
|
|
|
) { |
51
|
135 |
|
foreach ($commonMethods as $commonMethodsSpec) { |
52
|
135 |
|
list ($localNames, $callable, $args) = $commonMethodsSpec; |
53
|
|
|
|
54
|
135 |
|
if (in_array($childNode->localName, $localNames)) { |
55
|
135 |
|
return call_user_func_array($callable, $args); |
56
|
|
|
} |
57
|
45 |
|
} |
58
|
135 |
|
foreach ($commonArguments as $commonArgumentSpec) { |
59
|
135 |
|
list ($callables, $args) = $commonArgumentSpec; |
60
|
|
|
|
61
|
135 |
|
if (isset($callables[$childNode->localName])) { |
62
|
135 |
|
return call_user_func_array( |
63
|
135 |
|
$callables[$childNode->localName], |
64
|
90 |
|
$args |
65
|
45 |
|
); |
66
|
|
|
} |
67
|
45 |
|
} |
68
|
135 |
|
if (isset($methods[$childNode->localName])) { |
69
|
135 |
|
list ($callable, $args) = $methods[$childNode->localName]; |
70
|
|
|
|
71
|
135 |
|
return call_user_func_array($callable, $args); |
72
|
|
|
} |
73
|
135 |
|
} |
74
|
|
|
|
75
|
135 |
|
protected function maybeLoadSequenceFromElementContainer( |
76
|
|
|
BaseComplexType $type, |
77
|
|
|
DOMElement $childNode |
78
|
|
|
) { |
79
|
135 |
|
$this->maybeLoadThingFromThing( |
80
|
135 |
|
$type, |
81
|
135 |
|
$childNode, |
82
|
135 |
|
ElementContainer::class, |
83
|
90 |
|
'loadSequence' |
84
|
45 |
|
); |
85
|
135 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $instanceof |
89
|
|
|
* @param string $passTo |
90
|
|
|
*/ |
91
|
135 |
|
protected function maybeLoadThingFromThing( |
92
|
|
|
Type $type, |
93
|
|
|
DOMElement $childNode, |
94
|
|
|
$instanceof, |
95
|
|
|
$passTo |
96
|
|
|
) { |
97
|
135 |
|
if (! is_a($type, $instanceof, true)) { |
98
|
|
|
throw new RuntimeException( |
99
|
|
|
'Argument 1 passed to ' . |
100
|
|
|
__METHOD__ . |
101
|
|
|
' needs to be an instance of ' . |
102
|
|
|
$instanceof . |
103
|
|
|
' when passed onto ' . |
104
|
|
|
static::class . |
105
|
|
|
'::' . |
106
|
|
|
$passTo . |
107
|
|
|
'(), ' . |
108
|
|
|
get_class($type) . |
109
|
|
|
' given.' |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
135 |
|
$this->$passTo($type, $childNode); |
114
|
135 |
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param Closure|null $callback |
118
|
|
|
* |
119
|
|
|
* @return Closure |
120
|
|
|
*/ |
121
|
|
|
protected function makeCallbackCallback( |
122
|
|
|
Type $type, |
123
|
|
|
DOMElement $node, |
124
|
|
|
Closure $callbackCallback, |
125
|
|
|
$callback = null |
126
|
|
|
) { |
127
|
135 |
|
return function ( |
128
|
|
|
) use ( |
129
|
135 |
|
$type, |
130
|
135 |
|
$node, |
131
|
135 |
|
$callbackCallback, |
132
|
135 |
|
$callback |
133
|
|
|
) { |
134
|
135 |
|
$this->runCallbackAgainstDOMNodeList( |
135
|
135 |
|
$type, |
136
|
135 |
|
$node, |
137
|
135 |
|
$callbackCallback, |
138
|
90 |
|
$callback |
139
|
45 |
|
); |
140
|
135 |
|
}; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param Closure|null $callback |
145
|
|
|
*/ |
146
|
135 |
|
protected function runCallbackAgainstDOMNodeList( |
147
|
|
|
Type $type, |
148
|
|
|
DOMElement $node, |
149
|
|
|
Closure $againstNodeList, |
150
|
|
|
$callback = null |
151
|
|
|
) { |
152
|
135 |
|
$this->fillTypeNode($type, $node, true); |
153
|
|
|
|
154
|
135 |
|
foreach ($node->childNodes as $childNode) { |
155
|
135 |
|
if ($childNode instanceof DOMElement) { |
156
|
135 |
|
$againstNodeList( |
157
|
135 |
|
$node, |
158
|
90 |
|
$childNode |
159
|
45 |
|
); |
160
|
45 |
|
} |
161
|
45 |
|
} |
162
|
|
|
|
163
|
135 |
|
if ($callback) { |
164
|
135 |
|
call_user_func($callback, $type); |
165
|
45 |
|
} |
166
|
135 |
|
} |
167
|
|
|
|
168
|
135 |
|
protected function maybeLoadExtensionFromBaseComplexType( |
169
|
|
|
Type $type, |
170
|
|
|
DOMElement $childNode |
171
|
|
|
) { |
172
|
135 |
|
$this->maybeLoadThingFromThing( |
173
|
135 |
|
$type, |
174
|
135 |
|
$childNode, |
175
|
135 |
|
BaseComplexType::class, |
176
|
90 |
|
'loadExtension' |
177
|
45 |
|
); |
178
|
135 |
|
} |
179
|
|
|
} |
180
|
|
|
|