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: | use Nexus\Mcp\Arrayable; |
17: | |
18: | |
19: | |
20: | |
21: | abstract readonly class Message implements \JsonSerializable, Arrayable |
22: | { |
23: | final public const string JSON_RPC_VERSION = '2.0'; |
24: | |
25: | |
26: | |
27: | |
28: | public string $jsonrpc; |
29: | |
30: | public function __construct(string $jsonrpc) |
31: | { |
32: | if ('' === $jsonrpc) { |
33: | throw new \InvalidArgumentException('JSON-RPC version cannot be empty.'); |
34: | } |
35: | |
36: | if (self::JSON_RPC_VERSION !== $jsonrpc) { |
37: | throw new \InvalidArgumentException('Invalid JSON-RPC version.'); |
38: | } |
39: | |
40: | $this->jsonrpc = $jsonrpc; |
41: | } |
42: | |
43: | |
44: | |
45: | |
46: | #[\Override] |
47: | public function jsonSerialize(): array |
48: | { |
49: | return $this->toArray(); |
50: | } |
51: | } |
52: | |