PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.3
3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 All 196 releases
convertkit / vendor / wordpress / php-mcp-schema / src / Common / JsonRpc / DTO / JSONRPCResultResponse.php

JSONRPCResultResponse.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.3, at vendor/wordpress/php-mcp-schema/src/Common/JsonRpc/DTO/JSONRPCResultResponse.php

134 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace WP\McpSchema\Common\JsonRpc\DTO;
6
7 use WP\McpSchema\Common\AbstractDataTransferObject;
8 use WP\McpSchema\Common\JsonRpc\Union\JSONRPCResponseInterface;
9 use WP\McpSchema\Common\Protocol\DTO\Result;
10 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
11
12 /**
13 * A successful (non-error) response to a request.
14 *
15 * @since 2025-11-25
16 *
17 * @mcp-domain Common
18 * @mcp-subdomain JsonRpc
19 * @mcp-version 2025-11-25
20 */
21 class JSONRPCResultResponse extends AbstractDataTransferObject implements JSONRPCResponseInterface
22 {
23 use ValidatesRequiredFields;
24
25 /**
26 * @since 2025-11-25
27 *
28 * @var '2.0'
29 */
30 protected string $jsonrpc;
31
32 /**
33 * @since 2025-11-25
34 *
35 * @var string|number
36 */
37 protected $id;
38
39 /**
40 * @since 2025-11-25
41 *
42 * @var \WP\McpSchema\Common\Protocol\DTO\Result
43 */
44 protected Result $result;
45
46 /**
47 * @param '2.0' $jsonrpc @since 2025-11-25
48 * @param string|number $id @since 2025-11-25
49 * @param \WP\McpSchema\Common\Protocol\DTO\Result $result @since 2025-11-25
50 */
51 public function __construct(
52 string $jsonrpc,
53 $id,
54 Result $result
55 ) {
56 $this->jsonrpc = $jsonrpc;
57 $this->id = $id;
58 $this->result = $result;
59 }
60
61 /**
62 * Creates an instance from an array.
63 *
64 * @param array{
65 * jsonrpc: '2.0',
66 * id: string|number,
67 * result: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\Result
68 * } $data
69 * @phpstan-param array<string, mixed> $data
70 * @return self
71 */
72 public static function fromArray(array $data): self
73 {
74 self::assertRequired($data, ['jsonrpc', 'id', 'result']);
75
76 /** @var '2.0' $jsonrpc */
77 $jsonrpc = self::asString($data['jsonrpc']);
78
79 /** @var string|number $id */
80 $id = self::asStringOrNumber($data['id']);
81
82 /** @var \WP\McpSchema\Common\Protocol\DTO\Result $result */
83 $result = is_array($data['result'])
84 ? Result::fromArray(self::asArray($data['result']))
85 : $data['result'];
86
87 return new self(
88 $jsonrpc,
89 $id,
90 $result
91 );
92 }
93
94 /**
95 * Converts the instance to an array.
96 *
97 * @return array<string, mixed>
98 */
99 public function toArray(): array
100 {
101 $result = [];
102
103 $result['jsonrpc'] = $this->jsonrpc;
104 $result['id'] = $this->id;
105 $result['result'] = $this->result->toArray();
106
107 return $result;
108 }
109
110 /**
111 * @return '2.0'
112 */
113 public function getJsonrpc(): string
114 {
115 return $this->jsonrpc;
116 }
117
118 /**
119 * @return string|number
120 */
121 public function getId()
122 {
123 return $this->id;
124 }
125
126 /**
127 * @return \WP\McpSchema\Common\Protocol\DTO\Result
128 */
129 public function getResult(): Result
130 {
131 return $this->result;
132 }
133 }
134