1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace LaravelUi5\OData\Edm\Type;
6:
7: use LaravelUi5\OData\Edm\Contracts\Annotation\AnnotationInterface;
8: use LaravelUi5\OData\Edm\Contracts\Property\NavigationPropertyInterface;
9: use LaravelUi5\OData\Edm\Contracts\Property\PropertyInterface;
10: use LaravelUi5\OData\Edm\Contracts\Type\ComplexTypeInterface;
11: use LaravelUi5\OData\Edm\HasAnnotations;
12:
13: final readonly class ComplexType implements ComplexTypeInterface
14: {
15: use HasAnnotations;
16:
17: /**
18: * @param list<PropertyInterface> $declaredProperties
19: * @param list<NavigationPropertyInterface> $declaredNavigationProperties
20: * @param list<AnnotationInterface> $annotations
21: */
22: public function __construct(
23: private string $namespace,
24: private string $name,
25: private ?ComplexTypeInterface $baseType = null,
26: private bool $isAbstract = false,
27: private bool $isOpen = false,
28: private array $declaredProperties = [],
29: private array $declaredNavigationProperties = [],
30: array $annotations = [],
31: ) {
32: $this->annotations = $annotations;
33: }
34:
35: public function getName(): string
36: {
37: return $this->name;
38: }
39:
40: public function getQualifiedName(): string
41: {
42: return $this->namespace . '.' . $this->name;
43: }
44:
45: public function getBaseType(): ?ComplexTypeInterface
46: {
47: return $this->baseType;
48: }
49:
50: public function isAbstract(): bool
51: {
52: return $this->isAbstract;
53: }
54:
55: public function isOpen(): bool
56: {
57: return $this->isOpen;
58: }
59:
60: public function getDeclaredProperties(): array
61: {
62: return $this->declaredProperties;
63: }
64:
65: public function getProperty(string $name): ?PropertyInterface
66: {
67: foreach ($this->declaredProperties as $property) {
68: if ($property->getName() === $name) {
69: return $property;
70: }
71: }
72: return $this->baseType?->getProperty($name);
73: }
74:
75: public function getDeclaredNavigationProperties(): array
76: {
77: return $this->declaredNavigationProperties;
78: }
79:
80: public function getNavigationProperty(string $name): ?NavigationPropertyInterface
81: {
82: foreach ($this->declaredNavigationProperties as $navProp) {
83: if ($navProp->getName() === $name) {
84: return $navProp;
85: }
86: }
87: return $this->baseType?->getNavigationProperty($name);
88: }
89: }
90: