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 / Content / DTO / TextContent.php

TextContent.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/Content/DTO/TextContent.php

165 lines 4.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\Content\DTO;
6
7 use WP\McpSchema\Common\AbstractDataTransferObject;
8 use WP\McpSchema\Common\Protocol\DTO\Annotations;
9 use WP\McpSchema\Common\Protocol\Union\ContentBlockInterface;
10 use WP\McpSchema\Common\Protocol\Union\SamplingMessageContentBlockInterface;
11 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
12
13 /**
14 * Text provided to or from an LLM.
15 *
16 * @since 2024-11-05
17 * @last-updated 2025-11-25 (modified property: annotations)
18 *
19 * @mcp-domain Common
20 * @mcp-subdomain Content
21 * @mcp-version 2025-11-25
22 */
23 class TextContent extends AbstractDataTransferObject implements SamplingMessageContentBlockInterface, ContentBlockInterface
24 {
25 use ValidatesRequiredFields;
26
27 public const TYPE = 'text';
28
29 public const DISCRIMINATOR_FIELD = 'type';
30 public const DISCRIMINATOR_VALUE = 'text';
31
32 /**
33 * @since 2024-11-05
34 *
35 * @var 'text'
36 */
37 protected string $type;
38
39 /**
40 * The text content of the message.
41 *
42 * @since 2024-11-05
43 *
44 * @var string
45 */
46 protected string $text;
47
48 /**
49 * Optional annotations for the client.
50 *
51 * @since 2024-11-05
52 *
53 * @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null
54 */
55 protected ?Annotations $annotations;
56
57 /**
58 * See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage.
59 *
60 * @since 2025-06-18
61 *
62 * @var array<string, mixed>|null
63 */
64 protected ?array $_meta;
65
66 /**
67 * @param string $text @since 2024-11-05
68 * @param \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations @since 2024-11-05
69 * @param array<string, mixed>|null $_meta @since 2025-06-18
70 */
71 public function __construct(
72 string $text,
73 ?Annotations $annotations = null,
74 ?array $_meta = null
75 ) {
76 $this->type = self::TYPE;
77 $this->text = $text;
78 $this->annotations = $annotations;
79 $this->_meta = $_meta;
80 }
81
82 /**
83 * Creates an instance from an array.
84 *
85 * @param array{
86 * type: 'text',
87 * text: string,
88 * annotations?: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\Annotations|null,
89 * _meta?: array<string, mixed>|null
90 * } $data
91 * @phpstan-param array<string, mixed> $data
92 * @return self
93 */
94 public static function fromArray(array $data): self
95 {
96 self::assertRequired($data, ['text']);
97
98 /** @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations */
99 $annotations = isset($data['annotations'])
100 ? (is_array($data['annotations'])
101 ? Annotations::fromArray(self::asArray($data['annotations']))
102 : $data['annotations'])
103 : null;
104
105 return new self(
106 self::asString($data['text']),
107 $annotations,
108 self::asArrayOrNull($data['_meta'] ?? null)
109 );
110 }
111
112 /**
113 * Converts the instance to an array.
114 *
115 * @return array<string, mixed>
116 */
117 public function toArray(): array
118 {
119 $result = [];
120
121 $result['type'] = $this->type;
122 $result['text'] = $this->text;
123 if ($this->annotations !== null) {
124 $result['annotations'] = $this->annotations->toArray();
125 }
126 if ($this->_meta !== null) {
127 $result['_meta'] = $this->_meta;
128 }
129
130 return $result;
131 }
132
133 /**
134 * @return 'text'
135 */
136 public function getType(): string
137 {
138 return $this->type;
139 }
140
141 /**
142 * @return string
143 */
144 public function getText(): string
145 {
146 return $this->text;
147 }
148
149 /**
150 * @return \WP\McpSchema\Common\Protocol\DTO\Annotations|null
151 */
152 public function getAnnotations(): ?Annotations
153 {
154 return $this->annotations;
155 }
156
157 /**
158 * @return array<string, mixed>|null
159 */
160 public function get_meta(): ?array
161 {
162 return $this->_meta;
163 }
164 }
165