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
|
|
|
Schema $schema, |
66
|
|
|
DOMElement $node |
67
|
|
|
) { |
68
|
135 |
|
$group = new Group($schema, $node->getAttribute("name")); |
69
|
135 |
|
$group->setDoc(SchemaReader::getDocumentation($node)); |
70
|
|
|
|
71
|
135 |
|
if ($node->hasAttribute("maxOccurs")) { |
72
|
|
|
/** |
73
|
|
|
* @var GroupRef $group |
74
|
|
|
*/ |
75
|
|
|
$group = SchemaReader::maybeSetMax(new GroupRef($group), $node); |
76
|
|
|
} |
77
|
135 |
|
if ($node->hasAttribute("minOccurs")) { |
78
|
|
|
/** |
79
|
|
|
* @var GroupRef $group |
80
|
|
|
*/ |
81
|
|
|
$group = SchemaReader::maybeSetMin( |
82
|
|
|
$group instanceof GroupRef ? $group : new GroupRef($group), |
83
|
|
|
$node |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
135 |
|
$schema->addGroup($group); |
88
|
|
|
|
89
|
135 |
|
return $group; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return \Closure |
94
|
|
|
*/ |
95
|
135 |
|
public static function loadGroup( |
96
|
|
|
SchemaReader $reader, |
97
|
|
|
Schema $schema, |
98
|
|
|
DOMElement $node |
99
|
|
|
) { |
100
|
135 |
|
$group = static::loadGroupBeforeCheckingChildNodes( |
101
|
135 |
|
$schema, |
102
|
90 |
|
$node |
103
|
45 |
|
); |
104
|
|
|
|
105
|
90 |
|
static $methods = [ |
106
|
|
|
'sequence' => 'loadSequence', |
107
|
|
|
'choice' => 'loadSequence', |
108
|
|
|
'all' => 'loadSequence', |
109
|
45 |
|
]; |
110
|
|
|
|
111
|
135 |
|
return function () use ($reader, $group, $node, $methods) { |
112
|
135 |
|
foreach ($node->childNodes as $childNode) { |
113
|
135 |
|
$reader->maybeCallMethod( |
114
|
135 |
|
$methods, |
115
|
135 |
|
(string) $childNode->localName, |
116
|
135 |
|
$childNode, |
117
|
135 |
|
$group, |
118
|
90 |
|
$childNode |
119
|
45 |
|
); |
120
|
45 |
|
} |
121
|
135 |
|
}; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|