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 / Client / Elicitation / DTO / UntitledSingleSelectEnumSchema.php

UntitledSingleSelectEnumSchema.php in ZIP AI – AI Website Builder & AI Agent (Beta) 0.0.8, at lib/php-mcp-schema/src/Client/Elicitation/DTO/UntitledSingleSelectEnumSchema.php

180 lines 3.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\Client\Elicitation\DTO;
6
7 use WP\McpSchema\Client\Elicitation\Union\SingleSelectEnumSchemaInterface;
8 use WP\McpSchema\Common\AbstractDataTransferObject;
9 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
10
11 /**
12 * Schema for single-selection enumeration without display titles for options.
13 *
14 * @since 2025-11-25
15 *
16 * @mcp-domain Client
17 * @mcp-subdomain Elicitation
18 * @mcp-version 2025-11-25
19 */
20 class UntitledSingleSelectEnumSchema extends AbstractDataTransferObject implements SingleSelectEnumSchemaInterface
21 {
22 use ValidatesRequiredFields;
23
24 public const TYPE = 'string';
25
26 public const DISCRIMINATOR_FIELD = 'type';
27 public const DISCRIMINATOR_VALUE = 'string';
28
29 /**
30 * @since 2025-11-25
31 *
32 * @var 'string'
33 */
34 protected string $type;
35
36 /**
37 * Optional title for the enum field.
38 *
39 * @since 2025-11-25
40 *
41 * @var string|null
42 */
43 protected ?string $title;
44
45 /**
46 * Optional description for the enum field.
47 *
48 * @since 2025-11-25
49 *
50 * @var string|null
51 */
52 protected ?string $description;
53
54 /**
55 * Array of enum values to choose from.
56 *
57 * @since 2025-11-25
58 *
59 * @var array<string>
60 */
61 protected array $enum;
62
63 /**
64 * Optional default value.
65 *
66 * @since 2025-11-25
67 *
68 * @var string|null
69 */
70 protected ?string $default;
71
72 /**
73 * @param array<string> $enum @since 2025-11-25
74 * @param string|null $title @since 2025-11-25
75 * @param string|null $description @since 2025-11-25
76 * @param string|null $default @since 2025-11-25
77 */
78 public function __construct(
79 array $enum,
80 ?string $title = null,
81 ?string $description = null,
82 ?string $default = null
83 ) {
84 $this->type = self::TYPE;
85 $this->enum = $enum;
86 $this->title = $title;
87 $this->description = $description;
88 $this->default = $default;
89 }
90
91 /**
92 * Creates an instance from an array.
93 *
94 * @param array{
95 * type: 'string',
96 * title?: string|null,
97 * description?: string|null,
98 * enum: array<string>,
99 * default?: string|null
100 * } $data
101 * @phpstan-param array<string, mixed> $data
102 * @return self
103 */
104 public static function fromArray(array $data): self
105 {
106 self::assertRequired($data, ['enum']);
107
108 return new self(
109 self::asStringArray($data['enum']),
110 self::asStringOrNull($data['title'] ?? null),
111 self::asStringOrNull($data['description'] ?? null),
112 self::asStringOrNull($data['default'] ?? null)
113 );
114 }
115
116 /**
117 * Converts the instance to an array.
118 *
119 * @return array<string, mixed>
120 */
121 public function toArray(): array
122 {
123 $result = [];
124
125 $result['type'] = $this->type;
126 if ($this->title !== null) {
127 $result['title'] = $this->title;
128 }
129 if ($this->description !== null) {
130 $result['description'] = $this->description;
131 }
132 $result['enum'] = $this->enum;
133 if ($this->default !== null) {
134 $result['default'] = $this->default;
135 }
136
137 return $result;
138 }
139
140 /**
141 * @return 'string'
142 */
143 public function getType(): string
144 {
145 return $this->type;
146 }
147
148 /**
149 * @return string|null
150 */
151 public function getTitle(): ?string
152 {
153 return $this->title;
154 }
155
156 /**
157 * @return string|null
158 */
159 public function getDescription(): ?string
160 {
161 return $this->description;
162 }
163
164 /**
165 * @return array<string>
166 */
167 public function getEnum(): array
168 {
169 return $this->enum;
170 }
171
172 /**
173 * @return string|null
174 */
175 public function getDefault(): ?string
176 {
177 return $this->default;
178 }
179 }
180