| 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\EntityTypeInterface; |
| 11: | use LaravelUi5\OData\Edm\HasAnnotations; |
| 12: | |
| 13: | final readonly class EntityType implements EntityTypeInterface |
| 14: | { |
| 15: | use HasAnnotations; |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | public function __construct( |
| 24: | private string $namespace, |
| 25: | private string $name, |
| 26: | private ?EntityTypeInterface $baseType = null, |
| 27: | private bool $isAbstract = false, |
| 28: | private bool $isOpen = false, |
| 29: | private bool $hasStream = false, |
| 30: | private array $key = [], |
| 31: | private array $declaredProperties = [], |
| 32: | private array $declaredNavigationProperties = [], |
| 33: | array $annotations = [], |
| 34: | ) { |
| 35: | $this->annotations = $annotations; |
| 36: | } |
| 37: | |
| 38: | public function getName(): string |
| 39: | { |
| 40: | return $this->name; |
| 41: | } |
| 42: | |
| 43: | public function getQualifiedName(): string |
| 44: | { |
| 45: | return $this->namespace . '.' . $this->name; |
| 46: | } |
| 47: | |
| 48: | public function getBaseType(): ?EntityTypeInterface |
| 49: | { |
| 50: | return $this->baseType; |
| 51: | } |
| 52: | |
| 53: | public function isAbstract(): bool |
| 54: | { |
| 55: | return $this->isAbstract; |
| 56: | } |
| 57: | |
| 58: | public function isOpen(): bool |
| 59: | { |
| 60: | return $this->isOpen; |
| 61: | } |
| 62: | |
| 63: | public function hasStream(): bool |
| 64: | { |
| 65: | return $this->hasStream; |
| 66: | } |
| 67: | |
| 68: | public function getKey(): array |
| 69: | { |
| 70: | if ($this->key !== []) { |
| 71: | return $this->key; |
| 72: | } |
| 73: | return $this->baseType?->getKey() ?? []; |
| 74: | } |
| 75: | |
| 76: | public function getDeclaredProperties(): array |
| 77: | { |
| 78: | return $this->declaredProperties; |
| 79: | } |
| 80: | |
| 81: | public function getProperty(string $name): ?PropertyInterface |
| 82: | { |
| 83: | foreach ($this->declaredProperties as $property) { |
| 84: | if ($property->getName() === $name) { |
| 85: | return $property; |
| 86: | } |
| 87: | } |
| 88: | return $this->baseType?->getProperty($name); |
| 89: | } |
| 90: | |
| 91: | public function getDeclaredNavigationProperties(): array |
| 92: | { |
| 93: | return $this->declaredNavigationProperties; |
| 94: | } |
| 95: | |
| 96: | public function getNavigationProperty(string $name): ?NavigationPropertyInterface |
| 97: | { |
| 98: | foreach ($this->declaredNavigationProperties as $navProp) { |
| 99: | if ($navProp->getName() === $name) { |
| 100: | return $navProp; |
| 101: | } |
| 102: | } |
| 103: | return $this->baseType?->getNavigationProperty($name); |
| 104: | } |
| 105: | } |
| 106: | |