|
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
|
|
|
protected function maybeCallCallableWithArgs( |
|
46
|
|
|
DOMElement $childNode, |
|
47
|
|
|
array $commonMethods = [], |
|
48
|
|
|
array $methods = [], |
|
49
|
|
|
array $commonArguments = [] |
|
50
|
|
|
) { |
|
51
|
|
|
foreach ($commonMethods as $commonMethodsSpec) { |
|
52
|
|
|
list ($localNames, $callable, $args) = $commonMethodsSpec; |
|
53
|
|
|
|
|
54
|
|
|
if (in_array($childNode->localName, $localNames)) { |
|
55
|
|
|
return call_user_func_array($callable, $args); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
foreach ($commonArguments as $commonArgumentSpec) { |
|
59
|
|
|
list ($callables, $args) = $commonArgumentSpec; |
|
60
|
|
|
|
|
61
|
|
|
if (isset($callables[$childNode->localName])) { |
|
62
|
|
|
return call_user_func_array( |
|
63
|
|
|
$callables[$childNode->localName], |
|
64
|
|
|
$args |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
if (isset($methods[$childNode->localName])) { |
|
69
|
|
|
list ($callable, $args) = $methods[$childNode->localName]; |
|
70
|
|
|
|
|
71
|
|
|
return call_user_func_array($callable, $args); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
protected function maybeLoadSequenceFromElementContainer( |
|
76
|
|
|
BaseComplexType $type, |
|
77
|
|
|
DOMElement $childNode |
|
78
|
|
|
) { |
|
79
|
|
|
if (! ($type instanceof ElementContainer)) { |
|
80
|
|
|
throw new RuntimeException( |
|
81
|
|
|
'$type passed to ' . |
|
82
|
|
|
__FUNCTION__ . |
|
83
|
|
|
'expected to be an instance of ' . |
|
84
|
|
|
ElementContainer::class . |
|
85
|
|
|
' when child node localName is "group", ' . |
|
86
|
|
|
get_class($type) . |
|
87
|
|
|
' given.' |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
$this->loadSequence($type, $childNode); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param Closure|null $callback |
|
95
|
|
|
* |
|
96
|
|
|
* @return Closure |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function makeCallbackCallback( |
|
99
|
|
|
Type $type, |
|
100
|
|
|
DOMElement $node, |
|
101
|
|
|
Closure $callbackCallback, |
|
102
|
|
|
$callback = null |
|
103
|
|
|
) { |
|
104
|
|
|
return function ( |
|
105
|
|
|
) use ( |
|
106
|
|
|
$type, |
|
107
|
|
|
$node, |
|
108
|
|
|
$callbackCallback, |
|
109
|
|
|
$callback |
|
110
|
|
|
) { |
|
111
|
|
|
$this->runCallbackAgainstDOMNodeList( |
|
112
|
|
|
$type, |
|
113
|
|
|
$node, |
|
114
|
|
|
$callbackCallback, |
|
115
|
|
|
$callback |
|
116
|
|
|
); |
|
117
|
|
|
}; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param Closure|null $callback |
|
122
|
|
|
*/ |
|
123
|
|
|
protected function runCallbackAgainstDOMNodeList( |
|
124
|
|
|
Type $type, |
|
125
|
|
|
DOMElement $node, |
|
126
|
|
|
Closure $againstNodeList, |
|
127
|
|
|
$callback = null |
|
128
|
|
|
) { |
|
129
|
|
|
$this->fillTypeNode($type, $node, true); |
|
130
|
|
|
|
|
131
|
|
|
foreach ($node->childNodes as $childNode) { |
|
132
|
|
|
if ($childNode instanceof DOMElement) { |
|
133
|
|
|
$againstNodeList( |
|
134
|
|
|
$node, |
|
135
|
|
|
$childNode |
|
136
|
|
|
); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
if ($callback) { |
|
141
|
|
|
call_user_func($callback, $type); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
protected function maybeLoadExtensionFromBaseComplexType( |
|
146
|
|
|
Type $type, |
|
147
|
|
|
DOMElement $childNode |
|
148
|
|
|
) { |
|
149
|
|
|
if (! ($type instanceof BaseComplexType)) { |
|
150
|
|
|
throw new RuntimeException( |
|
151
|
|
|
'Argument 1 passed to ' . |
|
152
|
|
|
__METHOD__ . |
|
153
|
|
|
' needs to be an instance of ' . |
|
154
|
|
|
BaseComplexType::class . |
|
155
|
|
|
' when passed onto ' . |
|
156
|
|
|
static::class . |
|
157
|
|
|
'::loadExtension(), ' . |
|
158
|
|
|
get_class($type) . |
|
159
|
|
|
' given.' |
|
160
|
|
|
); |
|
161
|
|
|
} |
|
162
|
|
|
$this->loadExtension($type, $childNode); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|