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
|
45 |
|
protected function maybeCallCallableWithArgs( |
46
|
|
|
DOMElement $childNode, |
47
|
|
|
array $commonMethods = [], |
48
|
|
|
array $methods = [], |
49
|
|
|
array $commonArguments = [] |
50
|
|
|
) { |
51
|
45 |
|
foreach ($commonMethods as $commonMethodsSpec) { |
52
|
45 |
|
list ($localNames, $callable, $args) = $commonMethodsSpec; |
53
|
|
|
|
54
|
45 |
|
if (in_array($childNode->localName, $localNames)) { |
55
|
45 |
|
return call_user_func_array($callable, $args); |
56
|
|
|
} |
57
|
|
|
} |
58
|
45 |
|
foreach ($commonArguments as $commonArgumentSpec) { |
59
|
45 |
|
list ($callables, $args) = $commonArgumentSpec; |
60
|
|
|
|
61
|
45 |
|
if (isset($callables[$childNode->localName])) { |
62
|
45 |
|
return call_user_func_array( |
63
|
45 |
|
$callables[$childNode->localName], |
64
|
45 |
|
$args |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
45 |
|
if (isset($methods[$childNode->localName])) { |
69
|
45 |
|
list ($callable, $args) = $methods[$childNode->localName]; |
70
|
|
|
|
71
|
45 |
|
return call_user_func_array($callable, $args); |
72
|
|
|
} |
73
|
45 |
|
} |
74
|
|
|
|
75
|
45 |
|
protected function maybeLoadSequenceFromElementContainer( |
76
|
|
|
BaseComplexType $type, |
77
|
|
|
DOMElement $childNode |
78
|
|
|
) : void { |
79
|
45 |
|
$this->maybeLoadThingFromThing( |
80
|
45 |
|
$type, |
81
|
45 |
|
$childNode, |
82
|
45 |
|
ElementContainer::class, |
83
|
45 |
|
'loadSequence' |
84
|
|
|
); |
85
|
45 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $instanceof |
89
|
|
|
* @param string $passTo |
90
|
|
|
*/ |
91
|
45 |
|
protected function maybeLoadThingFromThing( |
92
|
|
|
Type $type, |
93
|
|
|
DOMElement $childNode, |
94
|
|
|
$instanceof, |
95
|
|
|
$passTo |
96
|
|
|
) { |
97
|
45 |
|
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
|
45 |
|
$this->$passTo($type, $childNode); |
114
|
45 |
|
} |
115
|
|
|
|
116
|
|
|
protected function makeCallbackCallback( |
117
|
|
|
Type $type, |
118
|
|
|
DOMElement $node, |
119
|
|
|
Closure $callbackCallback, |
120
|
|
|
Closure $callback = null |
121
|
|
|
) : Closure { |
122
|
45 |
|
return function ( |
123
|
|
|
) use ( |
124
|
45 |
|
$type, |
125
|
45 |
|
$node, |
126
|
45 |
|
$callbackCallback, |
127
|
45 |
|
$callback |
128
|
|
|
) : void { |
129
|
45 |
|
$this->runCallbackAgainstDOMNodeList( |
130
|
45 |
|
$type, |
131
|
45 |
|
$node, |
132
|
45 |
|
$callbackCallback, |
133
|
45 |
|
$callback |
134
|
|
|
); |
135
|
45 |
|
}; |
136
|
|
|
} |
137
|
|
|
|
138
|
45 |
|
protected function runCallbackAgainstDOMNodeList( |
139
|
|
|
Type $type, |
140
|
|
|
DOMElement $node, |
141
|
|
|
Closure $againstNodeList, |
142
|
|
|
Closure $callback = null |
143
|
|
|
) : void { |
144
|
45 |
|
$this->fillTypeNode($type, $node, true); |
145
|
|
|
|
146
|
45 |
|
foreach ($node->childNodes as $childNode) { |
147
|
45 |
|
if ($childNode instanceof DOMElement) { |
148
|
45 |
|
$againstNodeList( |
149
|
45 |
|
$node, |
150
|
45 |
|
$childNode |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
45 |
|
if ($callback) { |
156
|
45 |
|
call_user_func($callback, $type); |
157
|
|
|
} |
158
|
45 |
|
} |
159
|
|
|
|
160
|
45 |
|
protected function maybeLoadExtensionFromBaseComplexType( |
161
|
|
|
Type $type, |
162
|
|
|
DOMElement $childNode |
163
|
|
|
) : void { |
164
|
45 |
|
$this->maybeLoadThingFromThing( |
165
|
45 |
|
$type, |
166
|
45 |
|
$childNode, |
167
|
45 |
|
BaseComplexType::class, |
168
|
45 |
|
'loadExtension' |
169
|
|
|
); |
170
|
45 |
|
} |
171
|
|
|
} |
172
|
|
|
|