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 / Server / Resources / DTO / ReadResourceResult.php

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

99 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\Server\Resources\DTO;
6
7 use WP\McpSchema\Common\Protocol\DTO\Result;
8 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
9 use WP\McpSchema\Server\Lifecycle\Union\ServerResultInterface;
10
11 /**
12 * The server's response to a resources/read request from the client.
13 *
14 * @since 2024-11-05
15 * @last-updated 2025-11-25 (modified property: contents)
16 *
17 * @mcp-domain Server
18 * @mcp-subdomain Resources
19 * @mcp-version 2025-11-25
20 */
21 class ReadResourceResult extends Result implements ServerResultInterface
22 {
23 use ValidatesRequiredFields;
24
25 /**
26 * Wire keys this class models. Anything else is kept in $additionalProperties.
27 *
28 * @var array<int, string>
29 */
30 private const KNOWN_KEYS = ['_meta', 'contents'];
31
32 /**
33 * @since 2024-11-05
34 *
35 * @var array<\WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents>
36 */
37 protected array $contents;
38
39 /**
40 * @param array<\WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents> $contents @since 2024-11-05
41 * @param array<string, mixed>|null $_meta @since 2024-11-05
42 * @param array<string, mixed>|null $additionalProperties
43 */
44 public function __construct(
45 array $contents,
46 ?array $_meta = null,
47 ?array $additionalProperties = null
48 ) {
49 parent::__construct($_meta, $additionalProperties);
50 $this->contents = $contents;
51 }
52
53 /**
54 * Creates an instance from an array.
55 *
56 * @param array{
57 * _meta?: array<string, mixed>|null,
58 * contents: array<\WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents>
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, ['contents']);
66
67 /** @var array<\WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents> $contents */
68 $contents = self::asArray($data['contents']);
69
70 return new self(
71 $contents,
72 self::asArrayOrNull($data['_meta'] ?? null),
73 self::additionalFields($data, self::KNOWN_KEYS)
74 );
75 }
76
77 /**
78 * Converts the instance to an array.
79 *
80 * @return array<string, mixed>
81 */
82 public function toArray(): array
83 {
84 $result = parent::toArray();
85
86 $result['contents'] = array_map(static fn($item) => (is_object($item) && method_exists($item, 'toArray')) ? $item->toArray() : $item, $this->contents);
87
88 return $result;
89 }
90
91 /**
92 * @return array<\WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents>
93 */
94 public function getContents(): array
95 {
96 return $this->contents;
97 }
98 }
99