1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace LaravelUi5\OData\Edm\Annotation;
6:
7: use LaravelUi5\OData\Edm\Contracts\Annotation\PropertyValueInterface;
8: use LaravelUi5\OData\Edm\Contracts\Annotation\RecordAnnotationValueInterface;
9:
10: /**
11: * A record annotation value composed of named property values.
12: *
13: * Accepts the optional record type name followed by zero or more
14: * PropertyValueInterface instances as variadic arguments. The type name
15: * corresponds to the Type attribute on a CSDL <Record> element.
16: *
17: * @see RecordAnnotationValueInterface
18: * @see OData CSDL XML v4.01 ยง14.4.12 (Record)
19: */
20: final readonly class RecordAnnotationValue implements RecordAnnotationValueInterface
21: {
22: /** @var list<PropertyValueInterface> */
23: private array $propertyValues;
24:
25: public function __construct(
26: private ?string $type = null,
27: PropertyValueInterface ...$propertyValues,
28: ) {
29: $this->propertyValues = array_values($propertyValues);
30: }
31:
32: public function getType(): ?string
33: {
34: return $this->type;
35: }
36:
37: /** @return list<PropertyValueInterface> */
38: public function getPropertyValues(): array
39: {
40: return $this->propertyValues;
41: }
42:
43: public function getPropertyValue(string $name): ?PropertyValueInterface
44: {
45: foreach ($this->propertyValues as $pv) {
46: if ($pv->getProperty() === $name) {
47: return $pv;
48: }
49: }
50: return null;
51: }
52: }
53: