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 / Protocol / DTO / PingRequest.php

PingRequest.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/Protocol/DTO/PingRequest.php

111 lines 3.0 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\Protocol\DTO;
6
7 use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest;
8 use WP\McpSchema\Common\JsonRpc\DTO\RequestParams;
9 use WP\McpSchema\Common\Protocol\Union\ClientRequestInterface;
10 use WP\McpSchema\Common\Protocol\Union\ServerRequestInterface;
11 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
12
13 /**
14 * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.
15 *
16 * @since 2024-11-05
17 * @last-updated 2025-11-25 (modified property: params)
18 *
19 * @mcp-domain Common
20 * @mcp-subdomain Protocol
21 * @mcp-version 2025-11-25
22 */
23 class PingRequest extends JSONRPCRequest implements ClientRequestInterface, ServerRequestInterface
24 {
25 use ValidatesRequiredFields;
26
27 public const METHOD = 'ping';
28
29 public const DISCRIMINATOR_FIELD = 'method';
30 public const DISCRIMINATOR_VALUE = 'ping';
31
32 /**
33 * @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null
34 */
35 protected ?RequestParams $typedParams;
36
37 /**
38 * @param '2.0' $jsonrpc @since 2025-11-25
39 * @param string|number $id @since 2025-11-25
40 * @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null $params @since 2024-11-05
41 */
42 public function __construct(
43 string $jsonrpc,
44 $id,
45 ?RequestParams $params = null
46 ) {
47 parent::__construct(self::METHOD, $jsonrpc, $id, null);
48 $this->typedParams = $params;
49 }
50
51 /**
52 * Creates an instance from an array.
53 *
54 * @param array{
55 * jsonrpc: '2.0',
56 * id: string|number,
57 * method: 'ping',
58 * params?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null
59 * } $data
60 * @phpstan-param array<string, mixed> $data
61 * @return self
62 */
63 public static function fromArray(array $data): self
64 {
65 self::assertRequired($data, ['jsonrpc', 'id']);
66
67 /** @var '2.0' $jsonrpc */
68 $jsonrpc = self::asString($data['jsonrpc']);
69
70 /** @var string|number $id */
71 $id = self::asStringOrNumber($data['id']);
72
73 /** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null $params */
74 $params = isset($data['params'])
75 ? (is_array($data['params'])
76 ? RequestParams::fromArray(self::asArray($data['params']))
77 : $data['params'])
78 : null;
79
80 return new self(
81 $jsonrpc,
82 $id,
83 $params
84 );
85 }
86
87 /**
88 * Converts the instance to an array.
89 *
90 * @return array<string, mixed>
91 */
92 public function toArray(): array
93 {
94 $result = parent::toArray();
95
96 if ($this->typedParams !== null) {
97 $result['params'] = $this->typedParams->toArray();
98 }
99
100 return $result;
101 }
102
103 /**
104 * @return \WP\McpSchema\Common\JsonRpc\DTO\RequestParams|null
105 */
106 public function getTypedParams(): ?RequestParams
107 {
108 return $this->typedParams;
109 }
110 }
111