ameliabooking
/
vendor
/
wordpress
/
php-mcp-schema
/
src
/
Client
/
Elicitation
/
DTO
/
LegacyTitledEnumSchema.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
LegacyTitledEnumSchema.php
199 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\EnumSchemaInterface; |
| 8 | use WP\McpSchema\Common\AbstractDataTransferObject; |
| 9 | use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 10 | |
| 11 | /** |
| 12 | * Use TitledSingleSelectEnumSchema instead. |
| 13 | * This interface will be removed in a future version. |
| 14 | * |
| 15 | * @since 2025-11-25 |
| 16 | * |
| 17 | * @mcp-domain Client |
| 18 | * @mcp-subdomain Elicitation |
| 19 | * @mcp-version 2025-11-25 |
| 20 | */ |
| 21 | class LegacyTitledEnumSchema extends AbstractDataTransferObject implements EnumSchemaInterface |
| 22 | { |
| 23 | use ValidatesRequiredFields; |
| 24 | |
| 25 | public const TYPE = 'string'; |
| 26 | |
| 27 | public const DISCRIMINATOR_FIELD = 'type'; |
| 28 | public const DISCRIMINATOR_VALUE = 'string'; |
| 29 | |
| 30 | /** |
| 31 | * @since 2025-11-25 |
| 32 | * |
| 33 | * @var 'string' |
| 34 | */ |
| 35 | protected string $type; |
| 36 | |
| 37 | /** |
| 38 | * @since 2025-11-25 |
| 39 | * |
| 40 | * @var string|null |
| 41 | */ |
| 42 | protected ?string $title; |
| 43 | |
| 44 | /** |
| 45 | * @since 2025-11-25 |
| 46 | * |
| 47 | * @var string|null |
| 48 | */ |
| 49 | protected ?string $description; |
| 50 | |
| 51 | /** |
| 52 | * @since 2025-11-25 |
| 53 | * |
| 54 | * @var array<string> |
| 55 | */ |
| 56 | protected array $enum; |
| 57 | |
| 58 | /** |
| 59 | * (Legacy) Display names for enum values. |
| 60 | * Non-standard according to JSON schema 2020-12. |
| 61 | * |
| 62 | * @since 2025-11-25 |
| 63 | * |
| 64 | * @var array<string>|null |
| 65 | */ |
| 66 | protected ?array $enumNames; |
| 67 | |
| 68 | /** |
| 69 | * @since 2025-11-25 |
| 70 | * |
| 71 | * @var string|null |
| 72 | */ |
| 73 | protected ?string $default; |
| 74 | |
| 75 | /** |
| 76 | * @param array<string> $enum @since 2025-11-25 |
| 77 | * @param string|null $title @since 2025-11-25 |
| 78 | * @param string|null $description @since 2025-11-25 |
| 79 | * @param array<string>|null $enumNames @since 2025-11-25 |
| 80 | * @param string|null $default @since 2025-11-25 |
| 81 | */ |
| 82 | public function __construct( |
| 83 | array $enum, |
| 84 | ?string $title = null, |
| 85 | ?string $description = null, |
| 86 | ?array $enumNames = null, |
| 87 | ?string $default = null |
| 88 | ) { |
| 89 | $this->type = self::TYPE; |
| 90 | $this->enum = $enum; |
| 91 | $this->title = $title; |
| 92 | $this->description = $description; |
| 93 | $this->enumNames = $enumNames; |
| 94 | $this->default = $default; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Creates an instance from an array. |
| 99 | * |
| 100 | * @param array{ |
| 101 | * type: 'string', |
| 102 | * title?: string|null, |
| 103 | * description?: string|null, |
| 104 | * enum: array<string>, |
| 105 | * enumNames?: array<string>|null, |
| 106 | * default?: string|null |
| 107 | * } $data |
| 108 | * @phpstan-param array<string, mixed> $data |
| 109 | * @return self |
| 110 | */ |
| 111 | public static function fromArray(array $data): self |
| 112 | { |
| 113 | self::assertRequired($data, ['enum']); |
| 114 | |
| 115 | return new self( |
| 116 | self::asStringArray($data['enum']), |
| 117 | self::asStringOrNull($data['title'] ?? null), |
| 118 | self::asStringOrNull($data['description'] ?? null), |
| 119 | self::asStringArrayOrNull($data['enumNames'] ?? null), |
| 120 | self::asStringOrNull($data['default'] ?? null) |
| 121 | ); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Converts the instance to an array. |
| 126 | * |
| 127 | * @return array<string, mixed> |
| 128 | */ |
| 129 | public function toArray(): array |
| 130 | { |
| 131 | $result = []; |
| 132 | |
| 133 | $result['type'] = $this->type; |
| 134 | if ($this->title !== null) { |
| 135 | $result['title'] = $this->title; |
| 136 | } |
| 137 | if ($this->description !== null) { |
| 138 | $result['description'] = $this->description; |
| 139 | } |
| 140 | $result['enum'] = $this->enum; |
| 141 | if ($this->enumNames !== null) { |
| 142 | $result['enumNames'] = $this->enumNames; |
| 143 | } |
| 144 | if ($this->default !== null) { |
| 145 | $result['default'] = $this->default; |
| 146 | } |
| 147 | |
| 148 | return $result; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @return 'string' |
| 153 | */ |
| 154 | public function getType(): string |
| 155 | { |
| 156 | return $this->type; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @return string|null |
| 161 | */ |
| 162 | public function getTitle(): ?string |
| 163 | { |
| 164 | return $this->title; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * @return string|null |
| 169 | */ |
| 170 | public function getDescription(): ?string |
| 171 | { |
| 172 | return $this->description; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * @return array<string> |
| 177 | */ |
| 178 | public function getEnum(): array |
| 179 | { |
| 180 | return $this->enum; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * @return array<string>|null |
| 185 | */ |
| 186 | public function getEnumNames(): ?array |
| 187 | { |
| 188 | return $this->enumNames; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @return string|null |
| 193 | */ |
| 194 | public function getDefault(): ?string |
| 195 | { |
| 196 | return $this->default; |
| 197 | } |
| 198 | } |
| 199 |