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