| 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: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | final readonly class ProtocolVersion implements \JsonSerializable, \Stringable |
| 21: | { |
| 22: | public const string LATEST_PROTOCOL_VERSION = '2025-06-18'; |
| 23: | public const array SUPPORTED_PROTOCOL_VERSIONS = [ |
| 24: | self::LATEST_PROTOCOL_VERSION, |
| 25: | ]; |
| 26: | |
| 27: | private string $version; |
| 28: | private \DateTimeImmutable $versionAsDate; |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | public function __construct(string $version) |
| 34: | { |
| 35: | if (! \in_array($version, self::SUPPORTED_PROTOCOL_VERSIONS, true)) { |
| 36: | throw new \InvalidArgumentException(\sprintf( |
| 37: | 'Unsupported protocol version "%s". Supported versions are: "%s".', |
| 38: | $version, |
| 39: | implode('", "', self::SUPPORTED_PROTOCOL_VERSIONS), |
| 40: | )); |
| 41: | } |
| 42: | |
| 43: | $this->version = $version; |
| 44: | $this->versionAsDate = new \DateTimeImmutable($version, new \DateTimeZone('UTC')); |
| 45: | } |
| 46: | |
| 47: | #[\Override] |
| 48: | public function __toString(): string |
| 49: | { |
| 50: | return $this->version; |
| 51: | } |
| 52: | |
| 53: | #[\Override] |
| 54: | public function jsonSerialize(): string |
| 55: | { |
| 56: | return $this->version; |
| 57: | } |
| 58: | } |
| 59: | |