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