| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Message; |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | final readonly class RequestId implements \JsonSerializable, \Stringable |
| 20: | { |
| 21: | |
| 22: | |
| 23: | |
| 24: | public int|string $value; |
| 25: | |
| 26: | public function __construct(int|string $value) |
| 27: | { |
| 28: | if (\is_string($value) && trim($value) === '') { |
| 29: | throw new \InvalidArgumentException('Request ID must be a non-empty string or an integer.'); |
| 30: | } |
| 31: | |
| 32: | $this->value = $value; |
| 33: | } |
| 34: | |
| 35: | #[\Override] |
| 36: | public function __toString(): string |
| 37: | { |
| 38: | return (string) $this->value; |
| 39: | } |
| 40: | |
| 41: | #[\Override] |
| 42: | public function jsonSerialize(): int|string |
| 43: | { |
| 44: | return $this->value; |
| 45: | } |
| 46: | } |
| 47: | |