1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Attribute; |
3
|
|
|
|
4
|
|
|
use DOMElement; |
5
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReader; |
6
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReaderLoadAbstraction; |
7
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Schema; |
8
|
|
|
|
9
|
|
|
class Group implements AttributeItem, AttributeContainer |
10
|
|
|
{ |
11
|
|
|
use AttributeItemTrait; |
12
|
|
|
use AttributeContainerTrait; |
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
|
|
|
public function getSchema() |
57
|
|
|
{ |
58
|
|
|
return $this->schema; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $attr |
63
|
|
|
*/ |
64
|
135 |
|
public static function findSomethingLikeThis( |
65
|
|
|
SchemaReaderLoadAbstraction $useThis, |
66
|
|
|
Schema $schema, |
67
|
|
|
DOMElement $node, |
68
|
|
|
DOMElement $childNode, |
69
|
|
|
AttributeContainer $addToThis |
70
|
|
|
) { |
71
|
|
|
/** |
72
|
|
|
* @var AttributeItem $attribute |
73
|
|
|
*/ |
74
|
135 |
|
$attribute = $useThis->findSomething('findAttributeGroup', $schema, $node, $childNode->getAttribute("ref")); |
75
|
135 |
|
$addToThis->addAttribute($attribute); |
76
|
135 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return \Closure |
80
|
|
|
*/ |
81
|
135 |
|
public static function loadAttributeGroup( |
82
|
|
|
SchemaReaderLoadAbstraction $schemaReader, |
83
|
|
|
Schema $schema, |
84
|
|
|
DOMElement $node |
85
|
|
|
) { |
86
|
135 |
|
$attGroup = new self($schema, $node->getAttribute("name")); |
87
|
135 |
|
$attGroup->setDoc(SchemaReader::getDocumentation($node)); |
88
|
135 |
|
$schema->addAttributeGroup($attGroup); |
89
|
|
|
|
90
|
135 |
|
return function () use ($schemaReader, $schema, $node, $attGroup) { |
91
|
135 |
|
$limit = $node->childNodes->length; |
92
|
135 |
|
for ($i = 0; $i < $limit; $i += 1) { |
93
|
135 |
|
$childNode = $node->childNodes->item($i); |
94
|
135 |
|
switch ($childNode->localName) { |
95
|
135 |
|
case 'attribute': |
96
|
135 |
|
$attribute = Attribute::getAttributeFromAttributeOrRef( |
97
|
135 |
|
$schemaReader, |
98
|
135 |
|
$childNode, |
99
|
135 |
|
$schema, |
100
|
90 |
|
$node |
101
|
45 |
|
); |
102
|
135 |
|
$attGroup->addAttribute($attribute); |
103
|
135 |
|
break; |
104
|
135 |
|
case 'attributeGroup': |
105
|
3 |
|
self::findSomethingLikeThis( |
106
|
3 |
|
$schemaReader, |
107
|
3 |
|
$schema, |
108
|
3 |
|
$node, |
109
|
3 |
|
$childNode, |
110
|
2 |
|
$attGroup |
111
|
1 |
|
); |
112
|
3 |
|
break; |
113
|
45 |
|
} |
114
|
45 |
|
} |
115
|
135 |
|
}; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|