1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Element; |
6
|
|
|
|
7
|
|
|
use BadMethodCallException; |
8
|
|
|
use DOMElement; |
9
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReader; |
10
|
|
|
|
11
|
|
|
class GroupRef extends Group implements InterfaceSetMinMax |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Group |
15
|
|
|
*/ |
16
|
|
|
protected $wrapped; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var int |
20
|
|
|
*/ |
21
|
|
|
protected $min = 1; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var int |
25
|
|
|
*/ |
26
|
|
|
protected $max = 1; |
27
|
|
|
|
28
|
45 |
|
public function __construct(Group $group) |
29
|
|
|
{ |
30
|
45 |
|
parent::__construct($group->getSchema(), ''); |
31
|
45 |
|
$this->wrapped = $group; |
32
|
45 |
|
} |
33
|
|
|
|
34
|
|
|
public function getMin(): int |
35
|
|
|
{ |
36
|
|
|
return $this->min; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return $this |
41
|
|
|
*/ |
42
|
45 |
|
public function setMin(int $min): self |
43
|
|
|
{ |
44
|
45 |
|
$this->min = $min; |
45
|
|
|
|
46
|
45 |
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
public function getMax(): int |
50
|
|
|
{ |
51
|
1 |
|
return $this->max; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
45 |
|
public function setMax(int $max): self |
58
|
|
|
{ |
59
|
45 |
|
$this->max = $max; |
60
|
|
|
|
61
|
45 |
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public function getName(): string |
65
|
|
|
{ |
66
|
1 |
|
return $this->wrapped->getName(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return ElementItem[] |
71
|
|
|
*/ |
72
|
1 |
|
public function getElements(): array |
73
|
|
|
{ |
74
|
1 |
|
$elements = $this->wrapped->getElements(); |
75
|
1 |
|
if ($this->getMax() > 0 || $this->getMax() === -1) { |
76
|
1 |
|
foreach ($elements as $k => $element) { |
77
|
|
|
if (! ($element instanceof InterfaceSetMinMax)) { |
78
|
|
|
continue; |
79
|
|
|
} |
80
|
1 |
|
$e = clone $element; |
81
|
1 |
|
$e->setMax($this->getMax()); |
82
|
1 |
|
|
83
|
|
|
/** |
84
|
|
|
* @var Element|ElementRef|ElementSingle|GroupRef $e |
85
|
|
|
*/ |
86
|
1 |
|
$elements[$k] = $e; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $elements; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function addElement(ElementItem $element): void |
94
|
45 |
|
{ |
95
|
|
|
throw new BadMethodCallException("Can't add an element for a ref group"); |
96
|
|
|
} |
97
|
|
|
|
98
|
45 |
|
public static function loadGroupRef( |
99
|
45 |
|
Group $referenced, |
100
|
|
|
DOMElement $node |
101
|
45 |
|
): self { |
102
|
45 |
|
$ref = new self($referenced); |
103
|
|
|
$ref->setDoc(SchemaReader::getDocumentation($node)); |
104
|
45 |
|
|
105
|
|
|
SchemaReader::maybeSetMax($ref, $node); |
106
|
|
|
SchemaReader::maybeSetMin($ref, $node); |
107
|
|
|
|
108
|
|
|
return $ref; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|