|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\TestModel\Instance; |
|
4
|
|
|
|
|
5
|
|
|
use Xml\ModelBuilder; |
|
6
|
|
|
use Xml\Impl\Instance\ModelElementInstanceImpl; |
|
7
|
|
|
use Tests\TestModel\TestModelConstants; |
|
8
|
|
|
use Xml\Impl\Instance\ModelTypeInstanceContext; |
|
9
|
|
|
use Xml\Type\ModelTypeInstanceProviderInterface; |
|
10
|
|
|
|
|
11
|
|
|
abstract class RelationshipDefinition extends ModelElementInstanceImpl |
|
12
|
|
|
{ |
|
13
|
|
|
protected static $idAttr; |
|
14
|
|
|
protected static $animalRef; |
|
15
|
|
|
|
|
16
|
|
|
public static function registerType(ModelBuilder $modelBuilder): void |
|
17
|
|
|
{ |
|
18
|
|
|
$typeBuilder = $modelBuilder->defineType( |
|
19
|
|
|
RelationshipDefinition::class, |
|
20
|
|
|
TestModelConstants::TYPE_NAME_RELATIONSHIP_DEFINITION |
|
21
|
|
|
) |
|
22
|
|
|
->namespaceUri(TestModelConstants::MODEL_NAMESPACE) |
|
23
|
|
|
->abstractType(); |
|
24
|
|
|
|
|
25
|
|
|
self::$idAttr = $typeBuilder->stringAttribute(TestModelConstants::ATTRIBUTE_NAME_ID) |
|
26
|
|
|
->idAttribute() |
|
27
|
|
|
->build(); |
|
28
|
|
|
|
|
29
|
|
|
self::$animalRef = $typeBuilder->stringAttribute(TestModelConstants::ATTRIBUTE_NAME_ANIMAL_REF) |
|
30
|
|
|
->idAttributeReference(Animal::class) |
|
31
|
|
|
->build(); |
|
32
|
|
|
|
|
33
|
|
|
$typeBuilder->build(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function __construct(ModelTypeInstanceContext $instanceContext) |
|
37
|
|
|
{ |
|
38
|
|
|
parent::__construct($instanceContext); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getId(): string |
|
42
|
|
|
{ |
|
43
|
|
|
return self::$idAttr->getValue($this); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function setId(string $id): void |
|
47
|
|
|
{ |
|
48
|
|
|
self::$idAttr->setValue($this, $id); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function setAnimal(Animal $animalInRelationshipWith): void |
|
52
|
|
|
{ |
|
53
|
|
|
self::$animalRef->setReferenceTargetElement($this, $animalInRelationshipWith); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getAnimal(): Animal |
|
57
|
|
|
{ |
|
58
|
|
|
return self::$animalRef->getReferenceTargetElement($this); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|