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