| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema; |
| 15: | |
| 16: | use Nexus\Mcp\Schema\Enum\Role; |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | final readonly class Annotations implements \JsonSerializable, Arrayable |
| 28: | { |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | public function __construct( |
| 35: | public ?array $audience = null, |
| 36: | public ?\DateTimeImmutable $lastModified = null, |
| 37: | public ?float $priority = null, |
| 38: | ) { |
| 39: | if (isset($this->priority) && ($this->priority < 0.0 || $this->priority > 1.0)) { |
| 40: | throw new \InvalidArgumentException('$priority must be between 0.0 and 1.0.'); |
| 41: | } |
| 42: | } |
| 43: | |
| 44: | #[\Override] |
| 45: | public function toArray(): array |
| 46: | { |
| 47: | return array_filter([ |
| 48: | 'audience' => null === $this->audience ? null : array_map( |
| 49: | static fn(Role $role): string => $role->value, |
| 50: | $this->audience, |
| 51: | ), |
| 52: | 'lastModified' => $this->lastModified?->format('Y-m-d\TH:i:sp'), |
| 53: | 'priority' => $this->priority, |
| 54: | ], static fn(mixed $value): bool => null !== $value); |
| 55: | } |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | #[\Override] |
| 61: | public function jsonSerialize(): array |
| 62: | { |
| 63: | return $this->toArray(); |
| 64: | } |
| 65: | } |
| 66: | |