1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Attribute; |
3
|
|
|
|
4
|
|
|
use DOMElement; |
5
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReader; |
6
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Schema; |
7
|
|
|
|
8
|
|
|
class Group implements AttributeItem, AttributeContainer |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* |
13
|
|
|
* @var Schema |
14
|
|
|
*/ |
15
|
|
|
protected $schema; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string|null |
19
|
|
|
*/ |
20
|
|
|
protected $doc; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $name; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var AttributeItem[] |
29
|
|
|
*/ |
30
|
|
|
protected $attributes = array(); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string $name |
34
|
|
|
*/ |
35
|
135 |
|
public function __construct(Schema $schema, $name) |
36
|
|
|
{ |
37
|
135 |
|
$this->schema = $schema; |
38
|
135 |
|
$this->name = $name; |
39
|
135 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
135 |
|
public function getName() |
45
|
|
|
{ |
46
|
135 |
|
return $this->name; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $name |
51
|
|
|
* |
52
|
|
|
* @return $this |
53
|
|
|
*/ |
54
|
|
|
public function setName($name) |
55
|
|
|
{ |
56
|
|
|
$this->name = $name; |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
135 |
|
public function addAttribute(AttributeItem $attribute) |
61
|
|
|
{ |
62
|
135 |
|
$this->attributes[] = $attribute; |
63
|
135 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return AttributeItem[] |
67
|
|
|
*/ |
68
|
6 |
|
public function getAttributes() |
69
|
|
|
{ |
70
|
6 |
|
return $this->attributes; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string|null |
75
|
|
|
*/ |
76
|
|
|
public function getDoc() |
77
|
|
|
{ |
78
|
|
|
return $this->doc; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $doc |
83
|
|
|
* |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
135 |
|
public function setDoc($doc) |
87
|
|
|
{ |
88
|
135 |
|
$this->doc = $doc; |
89
|
135 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return Schema |
94
|
|
|
*/ |
95
|
|
|
public function getSchema() |
96
|
|
|
{ |
97
|
|
|
return $this->schema; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $attr |
102
|
|
|
*/ |
103
|
135 |
|
public static function findSomethingLikeThis( |
104
|
|
|
SchemaReader $useThis, |
105
|
|
|
Schema $schema, |
106
|
|
|
DOMElement $node, |
107
|
|
|
DOMElement $childNode, |
108
|
|
|
AttributeContainer $addToThis |
109
|
|
|
) { |
110
|
|
|
/** |
111
|
|
|
* @var AttributeItem $attribute |
112
|
|
|
*/ |
113
|
135 |
|
$attribute = $useThis->findSomething('findAttributeGroup', $schema, $node, $childNode->getAttribute("ref")); |
114
|
135 |
|
$addToThis->addAttribute($attribute); |
115
|
135 |
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return \Closure |
119
|
|
|
*/ |
120
|
135 |
|
public static function loadAttributeGroup( |
121
|
|
|
SchemaReader $schemaReader, |
122
|
|
|
Schema $schema, |
123
|
|
|
DOMElement $node |
124
|
|
|
) { |
125
|
135 |
|
$attGroup = new self($schema, $node->getAttribute("name")); |
126
|
135 |
|
$attGroup->setDoc(SchemaReader::getDocumentation($node)); |
127
|
135 |
|
$schema->addAttributeGroup($attGroup); |
128
|
|
|
|
129
|
135 |
|
return function () use ($schemaReader, $schema, $node, $attGroup) { |
130
|
135 |
|
foreach ($node->childNodes as $childNode) { |
131
|
135 |
|
switch ($childNode->localName) { |
132
|
135 |
|
case 'attribute': |
133
|
135 |
|
$attribute = Attribute::getAttributeFromAttributeOrRef( |
134
|
135 |
|
$schemaReader, |
135
|
135 |
|
$childNode, |
136
|
135 |
|
$schema, |
137
|
90 |
|
$node |
138
|
45 |
|
); |
139
|
135 |
|
$attGroup->addAttribute($attribute); |
140
|
135 |
|
break; |
141
|
135 |
|
case 'attributeGroup': |
142
|
3 |
|
self::findSomethingLikeThis( |
143
|
3 |
|
$schemaReader, |
144
|
3 |
|
$schema, |
145
|
3 |
|
$node, |
146
|
3 |
|
$childNode, |
147
|
2 |
|
$attGroup |
148
|
1 |
|
); |
149
|
91 |
|
break; |
150
|
45 |
|
} |
151
|
45 |
|
} |
152
|
135 |
|
}; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|