1
|
|
|
<?php |
2
|
|
|
namespace Goetas\Xsd\XsdToPhp\Jms; |
3
|
|
|
|
4
|
|
|
use Doctrine\Common\Inflector\Inflector; |
5
|
|
|
use Exception; |
6
|
|
|
use Goetas\Xsd\XsdToPhp\AbstractConverter; |
7
|
|
|
use Goetas\Xsd\XsdToPhp\Naming\NamingStrategy; |
8
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeContainer; |
9
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem; |
10
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\Element; |
11
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementContainer; |
12
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef; |
13
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementItem; |
14
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementRef; |
15
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Item; |
16
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Schema; |
17
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\SchemaItem; |
18
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\BaseComplexType; |
19
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType; |
20
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType; |
21
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\Type; |
22
|
|
|
|
23
|
|
|
class YamlConverter extends AbstractConverter |
24
|
|
|
{ |
25
|
|
|
|
26
|
23 |
|
public function __construct(NamingStrategy $namingStrategy) |
27
|
|
|
{ |
28
|
|
|
|
29
|
23 |
|
parent::__construct($namingStrategy); |
30
|
|
|
|
31
|
|
|
$this->addAliasMap("http://www.w3.org/2001/XMLSchema", "dateTime", function (Type $type) { |
|
|
|
|
32
|
3 |
|
return 'GoetasWebservices\Xsd\XsdToPhp\XMLSchema\DateTime'; |
33
|
23 |
|
}); |
34
|
|
|
$this->addAliasMap("http://www.w3.org/2001/XMLSchema", "time", function (Type $type) { |
|
|
|
|
35
|
|
|
return 'GoetasWebservices\Xsd\XsdToPhp\XMLSchema\Time'; |
36
|
23 |
|
}); |
37
|
|
|
$this->addAliasMap("http://www.w3.org/2001/XMLSchema", "date", function (Type $type) { |
|
|
|
|
38
|
|
|
return "DateTime<'Y-m-d'>"; |
39
|
23 |
|
}); |
40
|
23 |
|
} |
41
|
|
|
|
42
|
|
|
private $classes = []; |
43
|
|
|
|
44
|
23 |
View Code Duplication |
public function convert(array $schemas) |
|
|
|
|
45
|
|
|
{ |
46
|
23 |
|
$visited = array(); |
47
|
23 |
|
$this->classes = array(); |
48
|
23 |
|
foreach ($schemas as $schema) { |
49
|
23 |
|
$this->navigate($schema, $visited); |
50
|
23 |
|
} |
51
|
23 |
|
return $this->getTypes(); |
52
|
|
|
} |
53
|
|
|
|
54
|
12 |
|
private function flattAttributes(AttributeContainer $container) |
55
|
|
|
{ |
56
|
12 |
|
$items = array(); |
57
|
12 |
|
foreach ($container->getAttributes() as $attr) { |
58
|
5 |
|
if ($attr instanceof AttributeContainer) { |
59
|
1 |
|
$items = array_merge($items, $this->flattAttributes($attr)); |
60
|
1 |
|
} else { |
61
|
5 |
|
$items[] = $attr; |
62
|
|
|
} |
63
|
12 |
|
} |
64
|
12 |
|
return $items; |
65
|
|
|
} |
66
|
|
|
|
67
|
12 |
|
private function flattElements(ElementContainer $container) |
68
|
|
|
{ |
69
|
12 |
|
$items = array(); |
70
|
12 |
|
foreach ($container->getElements() as $attr) { |
71
|
12 |
|
if ($attr instanceof ElementContainer) { |
72
|
3 |
|
$items = array_merge($items, $this->flattElements($attr)); |
73
|
3 |
|
} else { |
74
|
12 |
|
$items[] = $attr; |
75
|
|
|
} |
76
|
12 |
|
} |
77
|
12 |
|
return $items; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* |
82
|
|
|
* @return PHPClass[] |
83
|
|
|
*/ |
84
|
|
|
public function getTypes() |
85
|
|
|
{ |
86
|
23 |
|
uasort($this->classes, function ($a, $b) { |
87
|
8 |
|
return strcmp(key($a), key($b)); |
88
|
23 |
|
}); |
89
|
|
|
|
90
|
23 |
|
$ret = array(); |
91
|
|
|
|
92
|
23 |
|
foreach ($this->classes as $definition) { |
93
|
22 |
|
$classname = key($definition["class"]); |
94
|
22 |
|
if (strpos($classname, '\\') !== false && (!isset($definition["skip"]) || !$definition["skip"])) { |
95
|
22 |
|
$ret[$classname] = $definition["class"]; |
96
|
22 |
|
} |
97
|
23 |
|
} |
98
|
|
|
|
99
|
23 |
|
return $ret; |
100
|
|
|
} |
101
|
|
|
|
102
|
23 |
View Code Duplication |
private function navigate(Schema $schema, array &$visited) |
|
|
|
|
103
|
|
|
{ |
104
|
23 |
|
if (isset($visited[spl_object_hash($schema)])) { |
105
|
|
|
return; |
106
|
|
|
} |
107
|
23 |
|
$visited[spl_object_hash($schema)] = true; |
108
|
|
|
|
109
|
23 |
|
foreach ($schema->getTypes() as $type) { |
110
|
10 |
|
$this->visitType($type); |
111
|
23 |
|
} |
112
|
23 |
|
foreach ($schema->getElements() as $element) { |
113
|
15 |
|
$this->visitElementDef($schema, $element); |
114
|
23 |
|
} |
115
|
|
|
|
116
|
23 |
|
foreach ($schema->getSchemas() as $schildSchema) { |
117
|
23 |
|
if (!in_array($schildSchema->getTargetNamespace(), $this->baseSchemas, true)) { |
118
|
2 |
|
$this->navigate($schildSchema, $visited); |
119
|
2 |
|
} |
120
|
23 |
|
} |
121
|
23 |
|
} |
122
|
|
|
|
123
|
17 |
|
private function visitTypeBase(&$class, &$data, Type $type, $name) |
124
|
|
|
{ |
125
|
17 |
|
if ($type instanceof BaseComplexType) { |
126
|
12 |
|
$this->visitBaseComplexType($class, $data, $type, $name); |
127
|
12 |
|
} |
128
|
17 |
|
if ($type instanceof ComplexType) { |
129
|
12 |
|
$this->visitComplexType($class, $data, $type); |
130
|
12 |
|
} |
131
|
17 |
|
if ($type instanceof SimpleType) { |
132
|
7 |
|
$this->visitSimpleType($class, $data, $type, $name); |
133
|
7 |
|
} |
134
|
17 |
|
} |
135
|
|
|
|
136
|
15 |
|
private function &visitElementDef(Schema $schema, ElementDef $element) |
137
|
|
|
{ |
138
|
15 |
|
if (!isset($this->classes[spl_object_hash($element)])) { |
139
|
15 |
|
$className = $this->findPHPNamespace($element) . "\\" . $this->getNamingStrategy()->getItemName($element); |
140
|
15 |
|
$class = array(); |
141
|
15 |
|
$data = array(); |
142
|
15 |
|
$ns = $className; |
143
|
15 |
|
$class[$ns] = &$data; |
144
|
15 |
|
$data["xml_root_name"] = $element->getName(); |
145
|
|
|
|
146
|
15 |
|
if ($schema->getTargetNamespace()) { |
147
|
14 |
|
$data["xml_root_namespace"] = $schema->getTargetNamespace(); |
148
|
14 |
|
} |
149
|
15 |
|
$this->classes[spl_object_hash($element)]["class"] = &$class; |
150
|
|
|
|
151
|
15 |
|
if (!$element->getType()->getName()) { |
152
|
8 |
|
$this->visitTypeBase($class, $data, $element->getType(), $element->getName()); |
153
|
8 |
|
} else { |
154
|
7 |
|
$this->handleClassExtension($class, $data, $element->getType(), $element->getName()); |
155
|
|
|
} |
156
|
15 |
|
} |
157
|
15 |
|
return $this->classes[spl_object_hash($element)]["class"]; |
158
|
|
|
} |
159
|
|
|
|
160
|
22 |
|
private function findPHPNamespace(SchemaItem $item) |
161
|
|
|
{ |
162
|
22 |
|
$schema = $item->getSchema(); |
163
|
|
|
|
164
|
22 |
View Code Duplication |
if (!isset($this->namespaces[$schema->getTargetNamespace()])) { |
|
|
|
|
165
|
|
|
throw new Exception(sprintf("Can't find a PHP namespace to '%s' namespace", $schema->getTargetNamespace())); |
166
|
|
|
} |
167
|
22 |
|
return $this->namespaces[$schema->getTargetNamespace()]; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
10 |
|
private function findPHPName(Type $type) |
172
|
|
|
{ |
173
|
10 |
|
$schema = $type->getSchema(); |
174
|
|
|
|
175
|
10 |
|
if ($alias = $this->getTypeAlias($type, $schema)) { |
176
|
|
|
return $alias; |
177
|
|
|
} |
178
|
|
|
|
179
|
10 |
|
$ns = $this->findPHPNamespace($type); |
180
|
10 |
|
$name = $this->getNamingStrategy()->getTypeName($type); |
181
|
|
|
|
182
|
10 |
|
return $ns . "\\" . $name; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
10 |
|
private function &visitType(Type $type, $force = false) |
187
|
|
|
{ |
188
|
|
|
|
189
|
10 |
|
if (!isset($this->classes[spl_object_hash($type)])) { |
190
|
|
|
|
191
|
10 |
|
if ($alias = $this->getTypeAlias($type)) { |
192
|
|
|
$class = array(); |
193
|
|
|
$class[$alias] = array(); |
194
|
|
|
|
195
|
|
|
$this->classes[spl_object_hash($type)]["class"] = &$class; |
196
|
|
|
$this->classes[spl_object_hash($type)]["skip"] = true; |
197
|
|
|
return $class; |
198
|
|
|
} |
199
|
|
|
|
200
|
10 |
|
$className = $this->findPHPName($type); |
201
|
|
|
|
202
|
10 |
|
$class = array(); |
203
|
10 |
|
$data = array(); |
204
|
|
|
|
205
|
10 |
|
$class[$className] = &$data; |
206
|
|
|
|
207
|
10 |
|
$this->classes[spl_object_hash($type)]["class"] = &$class; |
208
|
|
|
|
209
|
10 |
|
$this->visitTypeBase($class, $data, $type, $type->getName()); |
210
|
|
|
|
211
|
10 |
View Code Duplication |
if ($type instanceof SimpleType) { |
|
|
|
|
212
|
1 |
|
$this->classes[spl_object_hash($type)]["skip"] = true; |
213
|
1 |
|
return $class; |
214
|
|
|
} |
215
|
|
|
|
216
|
10 |
View Code Duplication |
if (!$force && ($this->isArrayType($type) || $this->isArrayNestedElement($type))) { |
|
|
|
|
217
|
1 |
|
$this->classes[spl_object_hash($type)]["skip"] = true; |
218
|
1 |
|
return $class; |
219
|
|
|
} |
220
|
10 |
View Code Duplication |
} elseif ($force) { |
|
|
|
|
221
|
2 |
|
if (!($type instanceof SimpleType) && !$this->getTypeAlias($type)) { |
222
|
2 |
|
$this->classes[spl_object_hash($type)]["skip"] = false; |
223
|
2 |
|
} |
224
|
2 |
|
} |
225
|
10 |
|
return $this->classes[spl_object_hash($type)]["class"]; |
226
|
|
|
} |
227
|
|
|
|
228
|
3 |
|
private function &visitTypeAnonymous(Type $type, $parentName, $parentClass) |
229
|
|
|
{ |
230
|
3 |
|
$class = array(); |
231
|
3 |
|
$data = array(); |
232
|
|
|
|
233
|
3 |
|
$name = $this->getNamingStrategy()->getAnonymousTypeName($type, $parentName); |
234
|
|
|
|
235
|
3 |
|
$class[key($parentClass) . "\\" . $name] = &$data; |
236
|
|
|
|
237
|
3 |
|
$this->visitTypeBase($class, $data, $type, $parentName); |
238
|
3 |
|
if ($parentName) { |
239
|
3 |
|
$this->classes[spl_object_hash($type)]["class"] = &$class; |
240
|
|
|
|
241
|
3 |
|
if ($type instanceof SimpleType) { |
242
|
1 |
|
$this->classes[spl_object_hash($type)]["skip"] = true; |
243
|
1 |
|
} |
244
|
3 |
|
} |
245
|
3 |
|
return $class; |
246
|
|
|
} |
247
|
|
|
|
248
|
12 |
|
private function visitComplexType(&$class, &$data, ComplexType $type) |
249
|
|
|
{ |
250
|
12 |
|
$schema = $type->getSchema(); |
251
|
12 |
|
if (!isset($data["properties"])) { |
252
|
|
|
$data["properties"] = array(); |
253
|
|
|
} |
254
|
12 |
|
foreach ($this->flattElements($type) as $element) { |
255
|
12 |
|
$data["properties"][$this->getNamingStrategy()->getPropertyName($element)] = $this->visitElement($class, $schema, $element); |
256
|
12 |
|
} |
257
|
12 |
|
} |
258
|
|
|
|
259
|
7 |
|
private function visitSimpleType(&$class, &$data, SimpleType $type, $name) |
260
|
|
|
{ |
261
|
7 |
|
if ($restriction = $type->getRestriction()) { |
262
|
7 |
|
$parent = $restriction->getBase(); |
263
|
7 |
|
if ($parent instanceof Type) { |
264
|
7 |
|
$this->handleClassExtension($class, $data, $parent, $name); |
265
|
7 |
|
} |
266
|
|
|
|
267
|
7 |
|
$checks = $restriction->getChecks(); |
268
|
7 |
|
if (count($checks) && isset($checks['enumeration'])) { |
269
|
1 |
|
$data['properties']['__value']['xml_element'] = ['cdata' => false]; |
270
|
1 |
|
} |
271
|
7 |
|
} elseif ($unions = $type->getUnions()) { |
272
|
1 |
|
foreach ($unions as $i => $unon) { |
273
|
1 |
|
$this->handleClassExtension($class, $data, $unon, $name . $i); |
274
|
1 |
|
break; |
275
|
1 |
|
} |
276
|
1 |
|
} |
277
|
7 |
|
} |
278
|
|
|
|
279
|
12 |
|
private function visitBaseComplexType(&$class, &$data, BaseComplexType $type, $name) |
280
|
|
|
{ |
281
|
12 |
|
$parent = $type->getParent(); |
282
|
12 |
|
if ($parent) { |
283
|
2 |
|
$parentType = $parent->getBase(); |
284
|
2 |
|
if ($parentType instanceof Type) { |
285
|
2 |
|
$this->handleClassExtension($class, $data, $parentType, $name); |
286
|
2 |
|
} |
287
|
2 |
|
} |
288
|
|
|
|
289
|
12 |
|
$schema = $type->getSchema(); |
290
|
12 |
|
if (!isset($data["properties"])) { |
291
|
12 |
|
$data["properties"] = array(); |
292
|
12 |
|
} |
293
|
12 |
|
foreach ($this->flattAttributes($type) as $attr) { |
294
|
5 |
|
$data["properties"][$this->getNamingStrategy()->getPropertyName($attr)] = $this->visitAttribute($class, $schema, $attr); |
295
|
12 |
|
} |
296
|
12 |
|
} |
297
|
|
|
|
298
|
14 |
|
private function handleClassExtension(&$class, &$data, Type $type, $parentName) |
299
|
|
|
{ |
300
|
14 |
|
if ($alias = $this->getTypeAlias($type)) { |
301
|
|
|
|
302
|
|
|
|
303
|
13 |
|
$property = array(); |
304
|
13 |
|
$property["expose"] = true; |
305
|
13 |
|
$property["xml_value"] = true; |
306
|
13 |
|
$property["access_type"] = "public_method"; |
307
|
13 |
|
$property["accessor"]["getter"] = "value"; |
308
|
13 |
|
$property["accessor"]["setter"] = "value"; |
309
|
13 |
|
$property["type"] = $alias; |
310
|
|
|
|
311
|
13 |
|
$data["properties"]["__value"] = $property; |
312
|
|
|
|
313
|
|
|
|
314
|
13 |
|
} else { |
315
|
2 |
|
$extension = $this->visitType($type, true); |
316
|
|
|
|
317
|
2 |
|
if (isset($extension['properties']['__value']) && count($extension['properties']) === 1) { |
318
|
|
|
$data["properties"]["__value"] = $extension['properties']['__value']; |
319
|
|
|
} else { |
320
|
2 |
|
if ($type instanceof SimpleType) { // @todo ?? basta come controllo? |
321
|
1 |
|
$property = array(); |
322
|
1 |
|
$property["expose"] = true; |
323
|
1 |
|
$property["xml_value"] = true; |
324
|
1 |
|
$property["access_type"] = "public_method"; |
325
|
1 |
|
$property["accessor"]["getter"] = "value"; |
326
|
1 |
|
$property["accessor"]["setter"] = "value"; |
327
|
|
|
|
328
|
1 |
|
if ($valueProp = $this->typeHasValue($type, $class, $parentName)) { |
329
|
1 |
|
$property["type"] = $valueProp; |
330
|
1 |
|
} else { |
331
|
1 |
|
$property["type"] = key($extension); |
332
|
|
|
} |
333
|
|
|
|
334
|
1 |
|
$data["properties"]["__value"] = $property; |
335
|
|
|
|
336
|
1 |
|
} |
337
|
|
|
} |
338
|
|
|
} |
339
|
14 |
|
} |
340
|
|
|
|
341
|
5 |
|
private function visitAttribute(&$class, Schema $schema, AttributeItem $attribute) |
342
|
|
|
{ |
343
|
5 |
|
$property = array(); |
344
|
5 |
|
$property["expose"] = true; |
345
|
5 |
|
$property["access_type"] = "public_method"; |
346
|
5 |
|
$property["serialized_name"] = $attribute->getName(); |
347
|
|
|
|
348
|
5 |
|
$property["accessor"]["getter"] = "get" . Inflector::classify($attribute->getName()); |
349
|
5 |
|
$property["accessor"]["setter"] = "set" . Inflector::classify($attribute->getName()); |
350
|
|
|
|
351
|
5 |
|
$property["xml_attribute"] = true; |
352
|
|
|
|
353
|
5 |
|
if ($alias = $this->getTypeAlias($attribute)) { |
354
|
|
|
$property["type"] = $alias; |
355
|
|
|
|
356
|
5 |
|
} elseif ($itemOfArray = $this->isArrayType($attribute->getType())) { |
|
|
|
|
357
|
|
|
|
358
|
|
View Code Duplication |
if ($valueProp = $this->typeHasValue($itemOfArray, $class, 'xx')) { |
|
|
|
|
359
|
|
|
$property["type"] = "GoetasWebservices\Xsd\XsdToPhp\Jms\SimpleListOf<" . $valueProp . ">"; |
360
|
|
|
} else { |
361
|
|
|
$property["type"] = "GoetasWebservices\Xsd\XsdToPhp\Jms\SimpleListOf<" . $this->findPHPName($itemOfArray) . ">"; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
$property["xml_list"]["inline"] = false; |
365
|
|
|
$property["xml_list"]["entry_name"] = $itemOfArray->getName(); |
366
|
|
|
if ($schema->getTargetNamespace()) { |
367
|
|
|
$property["xml_list"]["entry_namespace"] = $schema->getTargetNamespace(); |
368
|
|
|
} |
369
|
|
|
} else { |
370
|
5 |
|
$property["type"] = $this->findPHPClass($class, $attribute); |
|
|
|
|
371
|
|
|
} |
372
|
5 |
|
return $property; |
373
|
|
|
} |
374
|
|
|
|
375
|
3 |
|
private function typeHasValue(Type $type, $parentClass, $name) |
376
|
|
|
{ |
377
|
3 |
|
$collected = array(); |
|
|
|
|
378
|
|
|
do { |
379
|
3 |
|
if ($alias = $this->getTypeAlias($type)) { |
380
|
|
|
return $alias; |
381
|
|
|
} else { |
382
|
|
|
|
383
|
3 |
|
if ($type->getName()) { |
384
|
1 |
|
$parentClass = $this->visitType($type); |
385
|
1 |
|
} else { |
386
|
3 |
|
$parentClass = $this->visitTypeAnonymous($type, $name, $parentClass); |
387
|
|
|
} |
388
|
3 |
|
$props = reset($parentClass); |
389
|
3 |
|
if (isset($props['properties']['__value']) && count($props['properties']) === 1) { |
390
|
2 |
|
return $props['properties']['__value']['type']; |
391
|
|
|
} |
392
|
|
|
} |
393
|
3 |
|
} while (method_exists($type, 'getRestriction') && $type->getRestriction() && $type = $type->getRestriction()->getBase()); |
394
|
|
|
|
395
|
3 |
|
return false; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* |
400
|
|
|
* @param PHPClass $class |
401
|
|
|
* @param Schema $schema |
402
|
|
|
* @param Element $element |
403
|
|
|
* @param boolean $arrayize |
404
|
|
|
* @return \Goetas\Xsd\XsdToPhp\Structure\PHPProperty |
405
|
|
|
*/ |
406
|
12 |
|
private function visitElement(&$class, Schema $schema, ElementItem $element, $arrayize = true) |
407
|
|
|
{ |
408
|
12 |
|
$property = array(); |
409
|
12 |
|
$property["expose"] = true; |
410
|
12 |
|
$property["access_type"] = "public_method"; |
411
|
12 |
|
$property["serialized_name"] = $element->getName(); |
412
|
|
|
|
413
|
12 |
|
if ($element->getSchema()->getTargetNamespace()) { |
414
|
10 |
|
$property["xml_element"]["namespace"] = $element->getSchema()->getTargetNamespace(); |
415
|
10 |
|
} |
416
|
|
|
|
417
|
12 |
|
$property["accessor"]["getter"] = "get" . Inflector::classify($element->getName()); |
418
|
12 |
|
$property["accessor"]["setter"] = "set" . Inflector::classify($element->getName()); |
419
|
12 |
|
$t = $element->getType(); |
|
|
|
|
420
|
|
|
|
421
|
12 |
|
if ($arrayize) { |
422
|
|
|
|
423
|
12 |
|
if ($itemOfArray = $this->isArrayNestedElement($t)) { |
424
|
1 |
View Code Duplication |
if (!$t->getName()) { |
|
|
|
|
425
|
|
|
$classType = $this->visitTypeAnonymous($t, $element->getName(), $class); |
426
|
|
|
} else { |
427
|
1 |
|
$classType = $this->visitType($t); |
428
|
|
|
} |
429
|
|
|
|
430
|
1 |
|
$visited = $this->visitElement($classType, $schema, $itemOfArray, false); |
431
|
|
|
|
432
|
1 |
|
$property["type"] = "array<" . $visited["type"] . ">"; |
433
|
1 |
|
$property["xml_list"]["inline"] = false; |
434
|
1 |
|
$property["xml_list"]["skip_when_empty"] = $element->getMin() === 0; |
|
|
|
|
435
|
1 |
|
$property["xml_list"]["entry_name"] = $itemOfArray->getName(); |
436
|
1 |
|
if ($schema->getTargetNamespace()) { |
437
|
1 |
|
$property["xml_list"]["namespace"] = $schema->getTargetNamespace(); |
438
|
1 |
|
} |
439
|
1 |
|
return $property; |
440
|
12 |
|
} elseif ($itemOfArray = $this->isArrayType($t)) { |
441
|
|
|
|
442
|
|
|
if (!$t->getName()) { |
443
|
|
|
$visitedType = $this->visitTypeAnonymous($itemOfArray, $element->getName(), $class); |
444
|
|
|
|
445
|
|
View Code Duplication |
if ($prop = $this->typeHasValue($itemOfArray, $class, 'xx')) { |
|
|
|
|
446
|
|
|
$property["type"] = "array<" . $prop . ">"; |
447
|
|
|
} else { |
448
|
|
|
$property["type"] = "array<" . key($visitedType) . ">"; |
449
|
|
|
} |
450
|
|
|
} else { |
451
|
|
|
$this->visitType($itemOfArray); |
452
|
|
|
$property["type"] = "array<" . $this->findPHPName($itemOfArray) . ">"; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
$property["xml_list"]["inline"] = false; |
456
|
|
|
$property["xml_list"]["entry_name"] = $itemOfArray->getName(); |
457
|
|
|
if ($schema->getTargetNamespace()) { |
458
|
|
|
$property["xml_list"]["namespace"] = $schema->getTargetNamespace(); |
459
|
|
|
} |
460
|
|
|
return $property; |
461
|
12 |
|
} elseif ($this->isArrayElement($element)) { |
462
|
4 |
|
$property["xml_list"]["inline"] = true; |
463
|
4 |
|
$property["xml_list"]["entry_name"] = $element->getName(); |
464
|
4 |
|
if ($schema->getTargetNamespace()) { |
465
|
3 |
|
$property["xml_list"]["namespace"] = $schema->getTargetNamespace(); |
466
|
3 |
|
} |
467
|
|
|
|
468
|
4 |
|
$property["type"] = "array<" . $this->findPHPClass($class, $element) . ">"; |
|
|
|
|
469
|
4 |
|
return $property; |
470
|
|
|
} |
471
|
11 |
|
} |
472
|
|
|
|
473
|
12 |
|
$property["type"] = $this->findPHPClass($class, $element); |
|
|
|
|
474
|
12 |
|
return $property; |
475
|
|
|
} |
476
|
|
|
|
477
|
12 |
|
private function findPHPClass(&$class, Item $node) |
478
|
|
|
{ |
479
|
12 |
|
$type = $node->getType(); |
480
|
|
|
|
481
|
12 |
|
if ($alias = $this->getTypeAlias($node->getType())) { |
482
|
12 |
|
return $alias; |
483
|
|
|
} |
484
|
5 |
|
if ($node instanceof ElementRef) { |
485
|
4 |
|
$elementRef = $this->visitElementDef($node->getSchema(), $node->getReferencedElement()); |
486
|
4 |
|
return key($elementRef); |
487
|
|
|
} |
488
|
3 |
|
if ($valueProp = $this->typeHasValue($type, $class, '')) { |
489
|
2 |
|
return $valueProp; |
490
|
|
|
} |
491
|
3 |
View Code Duplication |
if (!$node->getType()->getName()) { |
|
|
|
|
492
|
2 |
|
$visited = $this->visitTypeAnonymous($node->getType(), $node->getName(), $class); |
493
|
2 |
|
} else { |
494
|
1 |
|
$visited = $this->visitType($node->getType()); |
495
|
|
|
} |
496
|
|
|
|
497
|
3 |
|
return key($visited); |
498
|
|
|
} |
499
|
|
|
} |
500
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.