ameliabooking
/
vendor
/
wordpress
/
php-mcp-schema
/
src
/
Client
/
Elicitation
/
DTO
/
StringSchema.php
ameliabooking
/
vendor
/
wordpress
/
php-mcp-schema
/
src
/
Client
/
Elicitation
/
DTO
Last commit date
BooleanSchema.php
1 month ago
ElicitRequest.php
1 month ago
ElicitRequestFormParams.php
1 month ago
ElicitRequestFormParamsRequestedSchema.php
1 month ago
ElicitRequestURLParams.php
1 month ago
ElicitResult.php
1 month ago
ElicitationCompleteNotification.php
1 month ago
ElicitationCompleteNotificationParams.php
1 month ago
LegacyTitledEnumSchema.php
1 month ago
NumberSchema.php
1 month ago
StringSchema.php
1 month ago
TitledMultiSelectEnumSchema.php
1 month ago
TitledMultiSelectEnumSchemaItems.php
1 month ago
TitledSingleSelectEnumSchema.php
1 month ago
UntitledMultiSelectEnumSchema.php
1 month ago
UntitledMultiSelectEnumSchemaItems.php
1 month ago
UntitledSingleSelectEnumSchema.php
1 month ago
StringSchema.php
222 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WP\McpSchema\Client\Elicitation\DTO; |
| 6 | |
| 7 | use WP\McpSchema\Client\Elicitation\Union\PrimitiveSchemaDefinitionInterface; |
| 8 | use WP\McpSchema\Common\AbstractDataTransferObject; |
| 9 | use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 10 | |
| 11 | /** |
| 12 | * @since 2025-06-18 |
| 13 | * @last-updated 2025-11-25 (added properties: default) |
| 14 | * |
| 15 | * @mcp-domain Client |
| 16 | * @mcp-subdomain Elicitation |
| 17 | * @mcp-version 2025-11-25 |
| 18 | */ |
| 19 | class StringSchema extends AbstractDataTransferObject implements PrimitiveSchemaDefinitionInterface |
| 20 | { |
| 21 | use ValidatesRequiredFields; |
| 22 | |
| 23 | public const TYPE = 'string'; |
| 24 | |
| 25 | public const DISCRIMINATOR_FIELD = 'type'; |
| 26 | public const DISCRIMINATOR_VALUE = 'string'; |
| 27 | |
| 28 | /** |
| 29 | * @since 2025-06-18 |
| 30 | * |
| 31 | * @var 'string' |
| 32 | */ |
| 33 | protected string $type; |
| 34 | |
| 35 | /** |
| 36 | * @since 2025-06-18 |
| 37 | * |
| 38 | * @var string|null |
| 39 | */ |
| 40 | protected ?string $title; |
| 41 | |
| 42 | /** |
| 43 | * @since 2025-06-18 |
| 44 | * |
| 45 | * @var string|null |
| 46 | */ |
| 47 | protected ?string $description; |
| 48 | |
| 49 | /** |
| 50 | * @since 2025-06-18 |
| 51 | * |
| 52 | * @var int|null |
| 53 | */ |
| 54 | protected ?int $minLength; |
| 55 | |
| 56 | /** |
| 57 | * @since 2025-06-18 |
| 58 | * |
| 59 | * @var int|null |
| 60 | */ |
| 61 | protected ?int $maxLength; |
| 62 | |
| 63 | /** |
| 64 | * @since 2025-06-18 |
| 65 | * |
| 66 | * @var 'email'|'uri'|'date'|'date-time'|null |
| 67 | */ |
| 68 | protected ?string $format; |
| 69 | |
| 70 | /** |
| 71 | * @since 2025-11-25 |
| 72 | * |
| 73 | * @var string|null |
| 74 | */ |
| 75 | protected ?string $default; |
| 76 | |
| 77 | /** |
| 78 | * @param string|null $title @since 2025-06-18 |
| 79 | * @param string|null $description @since 2025-06-18 |
| 80 | * @param int|null $minLength @since 2025-06-18 |
| 81 | * @param int|null $maxLength @since 2025-06-18 |
| 82 | * @param 'email'|'uri'|'date'|'date-time'|null $format @since 2025-06-18 |
| 83 | * @param string|null $default @since 2025-11-25 |
| 84 | */ |
| 85 | public function __construct( |
| 86 | ?string $title = null, |
| 87 | ?string $description = null, |
| 88 | ?int $minLength = null, |
| 89 | ?int $maxLength = null, |
| 90 | ?string $format = null, |
| 91 | ?string $default = null |
| 92 | ) { |
| 93 | $this->type = self::TYPE; |
| 94 | $this->title = $title; |
| 95 | $this->description = $description; |
| 96 | $this->minLength = $minLength; |
| 97 | $this->maxLength = $maxLength; |
| 98 | $this->format = $format; |
| 99 | $this->default = $default; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Creates an instance from an array. |
| 104 | * |
| 105 | * @param array{ |
| 106 | * type: 'string', |
| 107 | * title?: string|null, |
| 108 | * description?: string|null, |
| 109 | * minLength?: int|null, |
| 110 | * maxLength?: int|null, |
| 111 | * format?: 'email'|'uri'|'date'|'date-time'|null, |
| 112 | * default?: string|null |
| 113 | * } $data |
| 114 | * @phpstan-param array<string, mixed> $data |
| 115 | * @return self |
| 116 | */ |
| 117 | public static function fromArray(array $data): self |
| 118 | { |
| 119 | /** @var 'email'|'uri'|'date'|'date-time'|null $format */ |
| 120 | $format = isset($data['format']) |
| 121 | ? self::asStringOrNull($data['format']) |
| 122 | : null; |
| 123 | |
| 124 | return new self( |
| 125 | self::asStringOrNull($data['title'] ?? null), |
| 126 | self::asStringOrNull($data['description'] ?? null), |
| 127 | self::asIntOrNull($data['minLength'] ?? null), |
| 128 | self::asIntOrNull($data['maxLength'] ?? null), |
| 129 | $format, |
| 130 | self::asStringOrNull($data['default'] ?? null) |
| 131 | ); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Converts the instance to an array. |
| 136 | * |
| 137 | * @return array<string, mixed> |
| 138 | */ |
| 139 | public function toArray(): array |
| 140 | { |
| 141 | $result = []; |
| 142 | |
| 143 | $result['type'] = $this->type; |
| 144 | if ($this->title !== null) { |
| 145 | $result['title'] = $this->title; |
| 146 | } |
| 147 | if ($this->description !== null) { |
| 148 | $result['description'] = $this->description; |
| 149 | } |
| 150 | if ($this->minLength !== null) { |
| 151 | $result['minLength'] = $this->minLength; |
| 152 | } |
| 153 | if ($this->maxLength !== null) { |
| 154 | $result['maxLength'] = $this->maxLength; |
| 155 | } |
| 156 | if ($this->format !== null) { |
| 157 | $result['format'] = $this->format; |
| 158 | } |
| 159 | if ($this->default !== null) { |
| 160 | $result['default'] = $this->default; |
| 161 | } |
| 162 | |
| 163 | return $result; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * @return 'string' |
| 168 | */ |
| 169 | public function getType(): string |
| 170 | { |
| 171 | return $this->type; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * @return string|null |
| 176 | */ |
| 177 | public function getTitle(): ?string |
| 178 | { |
| 179 | return $this->title; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * @return string|null |
| 184 | */ |
| 185 | public function getDescription(): ?string |
| 186 | { |
| 187 | return $this->description; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * @return int|null |
| 192 | */ |
| 193 | public function getMinLength(): ?int |
| 194 | { |
| 195 | return $this->minLength; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * @return int|null |
| 200 | */ |
| 201 | public function getMaxLength(): ?int |
| 202 | { |
| 203 | return $this->maxLength; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * @return 'email'|'uri'|'date'|'date-time'|null |
| 208 | */ |
| 209 | public function getFormat(): ?string |
| 210 | { |
| 211 | return $this->format; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @return string|null |
| 216 | */ |
| 217 | public function getDefault(): ?string |
| 218 | { |
| 219 | return $this->default; |
| 220 | } |
| 221 | } |
| 222 |