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