|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\TestModel\Instance; |
|
4
|
|
|
|
|
5
|
|
|
use Xml\ModelBuilder; |
|
6
|
|
|
use Xml\Impl\Instance\{ |
|
7
|
|
|
ModelElementInstanceImpl, |
|
8
|
|
|
ModelTypeInstanceContext |
|
9
|
|
|
}; |
|
10
|
|
|
use Xml\Type\ModelTypeInstanceProviderInterface; |
|
11
|
|
|
use Tests\TestModel\TestModelConstants; |
|
12
|
|
|
|
|
13
|
|
|
class Bird extends FlyingAnimal |
|
14
|
|
|
{ |
|
15
|
|
|
protected static $eggColl; |
|
16
|
|
|
protected static $spouseRefsColl; |
|
17
|
|
|
protected static $guardEggRefCollection; |
|
18
|
|
|
protected static $canHaveExtendedWings; |
|
19
|
|
|
protected static $wings; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct(ModelTypeInstanceContext $instanceContext) |
|
22
|
|
|
{ |
|
23
|
|
|
parent::__construct($instanceContext); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public static function registerType(ModelBuilder $modelBuilder): void |
|
27
|
|
|
{ |
|
28
|
|
|
$typeBuilder = $modelBuilder->defineType( |
|
29
|
|
|
Bird::class, |
|
30
|
|
|
TestModelConstants::ELEMENT_NAME_BIRD |
|
31
|
|
|
) |
|
32
|
|
|
->namespaceUri(TestModelConstants::MODEL_NAMESPACE) |
|
33
|
|
|
->extendsType(FlyingAnimal::class) |
|
|
|
|
|
|
34
|
|
|
->instanceProvider( |
|
35
|
|
|
new class implements ModelTypeInstanceProviderInterface |
|
36
|
|
|
{ |
|
37
|
|
|
public function newInstance(ModelTypeInstanceContext $instanceContext): Bird |
|
38
|
|
|
{ |
|
39
|
|
|
return new Bird($instanceContext); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$sequence = $typeBuilder->sequence(); |
|
45
|
|
|
|
|
46
|
|
|
self::$eggColl = $sequence->elementCollection(Egg::class) |
|
47
|
|
|
->minOccurs(0) |
|
48
|
|
|
->maxOccurs(6) |
|
49
|
|
|
->build(); |
|
50
|
|
|
|
|
51
|
|
|
self::$spouseRefsColl = $sequence->element(SpouseRef::class) |
|
52
|
|
|
->qNameElementReference(Bird::class) |
|
53
|
|
|
->build(); |
|
54
|
|
|
|
|
55
|
|
|
self::$guardEggRefCollection = $sequence->elementCollection(GuardEgg::class) |
|
56
|
|
|
->idsElementReferenceCollection(Egg::class) |
|
57
|
|
|
->build(); |
|
58
|
|
|
|
|
59
|
|
|
self::$canHaveExtendedWings = $typeBuilder->booleanAttribute("canHaveExtendedWings") |
|
60
|
|
|
->namespace(TestModelConstants::NEWER_NAMESPACE) |
|
61
|
|
|
->build(); |
|
62
|
|
|
|
|
63
|
|
|
self::$wings = $sequence->element(Wings::class) |
|
64
|
|
|
->build(); |
|
65
|
|
|
|
|
66
|
|
|
$typeBuilder->build(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getEggs(): array |
|
70
|
|
|
{ |
|
71
|
|
|
return self::$eggColl->get($this); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getSpouse(): ?Bird |
|
75
|
|
|
{ |
|
76
|
|
|
return self::$spouseRefsColl->getReferenceTargetElement($this); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function setSpouse(Bird $bird): void |
|
80
|
|
|
{ |
|
81
|
|
|
self::$spouseRefsColl->setReferenceTargetElement($this, $bird); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function removeSpouse(): void |
|
85
|
|
|
{ |
|
86
|
|
|
self::$spouseRefsColl->clearReferenceTargetElement($this); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getSpouseRef(): SpouseRef |
|
90
|
|
|
{ |
|
91
|
|
|
return self::$spouseRefsColl->getReferenceSource($this); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getGuardedEggs(): array |
|
95
|
|
|
{ |
|
96
|
|
|
return self::$guardEggRefCollection->getReferenceTargetElements($this); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function addEgg(Egg $egg): void |
|
100
|
|
|
{ |
|
101
|
|
|
self::$eggColl->add($this, $egg); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function removeEgg(Egg $egg): void |
|
105
|
|
|
{ |
|
106
|
|
|
self::$eggColl->remove($this, $egg); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function clearEggs(): void |
|
110
|
|
|
{ |
|
111
|
|
|
self::$eggColl->clear($this); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function addGuardedEgg(Egg $egg): void |
|
115
|
|
|
{ |
|
116
|
|
|
self::$guardEggRefCollection->add($this, $egg); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function addGuardedEggRef(GuardEgg $egg): void |
|
120
|
|
|
{ |
|
121
|
|
|
self::$guardEggRefCollection->getReferenceSourceCollection()->add($this, $egg); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function removeGuardedEggRef(GuardEgg $egg): void |
|
125
|
|
|
{ |
|
126
|
|
|
self::$guardEggRefCollection->getReferenceSourceCollection()->remove($this, $egg); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function clearGuardedEggRefs(): void |
|
130
|
|
|
{ |
|
131
|
|
|
self::$guardEggRefCollection->getReferenceSourceCollection()->clear($this); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function getGuardedEggRefs(): array |
|
135
|
|
|
{ |
|
136
|
|
|
return self::$guardEggRefCollection->getReferenceSourceCollection()->get($this); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function canHaveExtendedWings(): bool |
|
140
|
|
|
{ |
|
141
|
|
|
return self::$canHaveExtendedWings->getValue($this); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function setCanHaveExtendedWings(bool $b): void |
|
145
|
|
|
{ |
|
146
|
|
|
self::$canHaveExtendedWings->setValue($this, $b); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function getWings(): Wings |
|
150
|
|
|
{ |
|
151
|
|
|
return self::$wings->getChild($this); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function setWings(Wings $w): void |
|
155
|
|
|
{ |
|
156
|
|
|
self::$wings->setChild($this, $w); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|