1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace LaravelUi5\OData\Edm;
6:
7: use LaravelUi5\OData\Edm\Contracts\Annotation\AnnotationInterface;
8: use LaravelUi5\OData\Edm\Contracts\IncludedSchemaInterface;
9: use LaravelUi5\OData\Edm\Contracts\ReferenceInterface;
10:
11: final readonly class Reference implements ReferenceInterface
12: {
13: use HasAnnotations;
14:
15: /**
16: * @param list<IncludedSchemaInterface> $includes
17: * @param list<AnnotationInterface> $annotations
18: */
19: public function __construct(
20: private string $uri,
21: private array $includes = [],
22: array $annotations = [],
23: ) {
24: $this->annotations = $annotations;
25: }
26:
27: public function getUri(): string
28: {
29: return $this->uri;
30: }
31:
32: public function getIncludes(): array
33: {
34: return $this->includes;
35: }
36:
37: public function getInclude(string $namespace): ?IncludedSchemaInterface
38: {
39: foreach ($this->includes as $include) {
40: if ($include->getNamespace() === $namespace) {
41: return $include;
42: }
43: }
44: return null;
45: }
46:
47: /**
48: * Matches by fully qualified term name only. Alias resolution is not
49: * performed because Reference has no back-pointer to the enclosing
50: * EdmxInterface, and annotations on <edmx:Reference> elements are
51: * practically never present in real-world documents.
52: */
53: public function getAnnotation(string $term, ?string $qualifier = null): ?AnnotationInterface
54: {
55: foreach ($this->annotations as $annotation) {
56: if ($annotation->getTerm() === $term && $annotation->getQualifier() === $qualifier) {
57: return $annotation;
58: }
59: }
60: return null;
61: }
62: }
63: