PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / trunk
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). vtrunk
3.0.3 3.0.2 3.0.1 trunk 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.91 2.7.92 2.7.93 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0
commercebird / vendor / wordpress / php-mcp-schema / src / Common / JsonRpc / DTO / JSONRPCResultResponse.php
commercebird / vendor / wordpress / php-mcp-schema / src / Common / JsonRpc / DTO Last commit date
Error.php 3 months ago JSONRPCErrorResponse.php 3 months ago JSONRPCNotification.php 3 months ago JSONRPCRequest.php 3 months ago JSONRPCResultResponse.php 3 months ago Notification.php 3 months ago NotificationParams.php 3 months ago Request.php 3 months ago RequestParams.php 3 months ago RequestParamsMeta.php 3 months ago
JSONRPCResultResponse.php
134 lines
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