PluginProbe
ZIP AI – AI Website Builder & AI Agent (Beta) / 0.0.8
ZIP AI – AI Website Builder & AI Agent (Beta) v0.0.8
0.0.10 0.0.9 trunk 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8
zip-ai / lib / php-mcp-schema / src / Common / Protocol / DTO / InitializedNotification.php

InitializedNotification.php in ZIP AI – AI Website Builder & AI Agent (Beta) 0.0.8, at lib/php-mcp-schema/src/Common/Protocol/DTO/InitializedNotification.php

103 lines 2.8 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\JSONRPCNotification;
8 use WP\McpSchema\Common\JsonRpc\DTO\NotificationParams;
9 use WP\McpSchema\Common\Protocol\Union\ClientNotificationInterface;
10 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
11
12 /**
13 * This notification is sent from the client to the server after initialization has finished.
14 *
15 * @since 2024-11-05
16 * @last-updated 2025-11-25 (modified property: params)
17 *
18 * @mcp-domain Common
19 * @mcp-subdomain Protocol
20 * @mcp-version 2025-11-25
21 */
22 class InitializedNotification extends JSONRPCNotification implements ClientNotificationInterface
23 {
24 use ValidatesRequiredFields;
25
26 public const METHOD = 'notifications/initialized';
27
28 public const DISCRIMINATOR_FIELD = 'method';
29 public const DISCRIMINATOR_VALUE = 'notifications/initialized';
30
31 /**
32 * @var \WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null
33 */
34 protected ?NotificationParams $typedParams;
35
36 /**
37 * @param '2.0' $jsonrpc @since 2025-11-25
38 * @param \WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null $params @since 2024-11-05
39 */
40 public function __construct(
41 string $jsonrpc,
42 ?NotificationParams $params = null
43 ) {
44 parent::__construct(self::METHOD, $jsonrpc, null);
45 $this->typedParams = $params;
46 }
47
48 /**
49 * Creates an instance from an array.
50 *
51 * @param array{
52 * jsonrpc: '2.0',
53 * method: 'notifications/initialized',
54 * params?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null
55 * } $data
56 * @phpstan-param array<string, mixed> $data
57 * @return self
58 */
59 public static function fromArray(array $data): self
60 {
61 self::assertRequired($data, ['jsonrpc']);
62
63 /** @var '2.0' $jsonrpc */
64 $jsonrpc = self::asString($data['jsonrpc']);
65
66 /** @var \WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null $params */
67 $params = isset($data['params'])
68 ? (is_array($data['params'])
69 ? NotificationParams::fromArray(self::asArray($data['params']))
70 : $data['params'])
71 : null;
72
73 return new self(
74 $jsonrpc,
75 $params
76 );
77 }
78
79 /**
80 * Converts the instance to an array.
81 *
82 * @return array<string, mixed>
83 */
84 public function toArray(): array
85 {
86 $result = parent::toArray();
87
88 if ($this->typedParams !== null) {
89 $result['params'] = $this->typedParams->toArray();
90 }
91
92 return $result;
93 }
94
95 /**
96 * @return \WP\McpSchema\Common\JsonRpc\DTO\NotificationParams|null
97 */
98 public function getTypedParams(): ?NotificationParams
99 {
100 return $this->typedParams;
101 }
102 }
103