1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Element; |
3
|
|
|
|
4
|
|
|
use DOMElement; |
5
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItemTrait; |
6
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Schema; |
7
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReader; |
8
|
|
|
|
9
|
|
|
class Group implements ElementItem, ElementContainer |
10
|
|
|
{ |
11
|
|
|
use AttributeItemTrait; |
12
|
|
|
use ElementContainerTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* |
16
|
|
|
* @var Schema |
17
|
|
|
*/ |
18
|
|
|
protected $schema; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string|null |
22
|
|
|
*/ |
23
|
|
|
protected $doc; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $name |
27
|
|
|
*/ |
28
|
135 |
|
public function __construct(Schema $schema, $name) |
29
|
|
|
{ |
30
|
135 |
|
$this->schema = $schema; |
31
|
135 |
|
$this->name = $name; |
32
|
135 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return string|null |
36
|
|
|
*/ |
37
|
|
|
public function getDoc() |
38
|
|
|
{ |
39
|
|
|
return $this->doc; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $doc |
44
|
|
|
* |
45
|
|
|
* @return $this |
46
|
|
|
*/ |
47
|
135 |
|
public function setDoc($doc) |
48
|
|
|
{ |
49
|
135 |
|
$this->doc = $doc; |
50
|
135 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return Schema |
55
|
|
|
*/ |
56
|
135 |
|
public function getSchema() |
57
|
|
|
{ |
58
|
135 |
|
return $this->schema; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return Group|GroupRef |
63
|
|
|
*/ |
64
|
135 |
|
protected static function loadGroupBeforeCheckingChildNodes( |
65
|
|
|
SchemaReader $reader, |
|
|
|
|
66
|
|
|
Schema $schema, |
67
|
|
|
DOMElement $node |
68
|
|
|
) { |
69
|
135 |
|
$group = new Group($schema, $node->getAttribute("name")); |
70
|
135 |
|
$group->setDoc(SchemaReader::getDocumentation($node)); |
71
|
|
|
|
72
|
135 |
|
if ($node->hasAttribute("maxOccurs")) { |
73
|
|
|
/** |
74
|
|
|
* @var GroupRef $group |
75
|
|
|
*/ |
76
|
|
|
$group = SchemaReader::maybeSetMax(new GroupRef($group), $node); |
77
|
|
|
} |
78
|
135 |
|
if ($node->hasAttribute("minOccurs")) { |
79
|
|
|
/** |
80
|
|
|
* @var GroupRef $group |
81
|
|
|
*/ |
82
|
|
|
$group = SchemaReader::maybeSetMin( |
83
|
|
|
$group instanceof GroupRef ? $group : new GroupRef($group), |
84
|
|
|
$node |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
135 |
|
$schema->addGroup($group); |
89
|
|
|
|
90
|
135 |
|
return $group; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return \Closure |
95
|
|
|
*/ |
96
|
135 |
|
public static function loadGroup( |
97
|
|
|
SchemaReader $reader, |
98
|
|
|
Schema $schema, |
99
|
|
|
DOMElement $node |
100
|
|
|
) { |
101
|
135 |
|
$group = static::loadGroupBeforeCheckingChildNodes( |
102
|
135 |
|
$reader, |
103
|
135 |
|
$schema, |
104
|
90 |
|
$node |
105
|
45 |
|
); |
106
|
|
|
|
107
|
90 |
|
static $methods = [ |
108
|
|
|
'sequence' => 'loadSequence', |
109
|
|
|
'choice' => 'loadSequence', |
110
|
|
|
'all' => 'loadSequence', |
111
|
45 |
|
]; |
112
|
|
|
|
113
|
135 |
|
return function () use ($reader, $group, $node, $methods) { |
114
|
135 |
|
foreach ($node->childNodes as $childNode) { |
115
|
135 |
|
$reader->maybeCallMethod( |
116
|
135 |
|
$methods, |
117
|
135 |
|
(string) $childNode->localName, |
118
|
135 |
|
$childNode, |
119
|
135 |
|
$group, |
120
|
90 |
|
$childNode |
121
|
45 |
|
); |
122
|
45 |
|
} |
123
|
135 |
|
}; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.