| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace LaravelUi5\OData\Edm\Container; |
| 6: | |
| 7: | use LaravelUi5\OData\Edm\Contracts\Annotation\AnnotationInterface; |
| 8: | use LaravelUi5\OData\Edm\Contracts\Container\EntityContainerInterface; |
| 9: | use LaravelUi5\OData\Edm\Contracts\Container\EntitySetInterface; |
| 10: | use LaravelUi5\OData\Edm\Contracts\Container\FunctionImportInterface; |
| 11: | use LaravelUi5\OData\Edm\Contracts\Container\SingletonInterface; |
| 12: | use LaravelUi5\OData\Edm\HasAnnotations; |
| 13: | |
| 14: | final readonly class EntityContainer implements EntityContainerInterface |
| 15: | { |
| 16: | use HasAnnotations; |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | public function __construct( |
| 25: | private string $name, |
| 26: | private array $entitySets = [], |
| 27: | private array $singletons = [], |
| 28: | private array $functionImports = [], |
| 29: | private ?string $extendsName = null, |
| 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 getEntitySets(): array |
| 41: | { |
| 42: | return $this->entitySets; |
| 43: | } |
| 44: | |
| 45: | public function getEntitySet(string $name): ?EntitySetInterface |
| 46: | { |
| 47: | foreach ($this->entitySets as $entitySet) { |
| 48: | if ($entitySet->getName() === $name) { |
| 49: | return $entitySet; |
| 50: | } |
| 51: | } |
| 52: | return null; |
| 53: | } |
| 54: | |
| 55: | public function getSingletons(): array |
| 56: | { |
| 57: | return $this->singletons; |
| 58: | } |
| 59: | |
| 60: | public function getSingleton(string $name): ?SingletonInterface |
| 61: | { |
| 62: | foreach ($this->singletons as $singleton) { |
| 63: | if ($singleton->getName() === $name) { |
| 64: | return $singleton; |
| 65: | } |
| 66: | } |
| 67: | return null; |
| 68: | } |
| 69: | |
| 70: | public function getFunctionImports(): array |
| 71: | { |
| 72: | return $this->functionImports; |
| 73: | } |
| 74: | |
| 75: | public function getFunctionImport(string $name): ?FunctionImportInterface |
| 76: | { |
| 77: | foreach ($this->functionImports as $import) { |
| 78: | if ($import->getName() === $name) { |
| 79: | return $import; |
| 80: | } |
| 81: | } |
| 82: | return null; |
| 83: | } |
| 84: | |
| 85: | public function getExtendsName(): ?string |
| 86: | { |
| 87: | return $this->extendsName; |
| 88: | } |
| 89: | } |
| 90: | |