ameliabooking
/
vendor
/
wordpress
/
php-mcp-schema
/
src
/
Client
/
Elicitation
/
DTO
/
ElicitResult.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
ElicitResult.php
120 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WP\McpSchema\Client\Elicitation\DTO; |
| 6 | |
| 7 | use WP\McpSchema\Client\Lifecycle\Union\ClientResultInterface; |
| 8 | use WP\McpSchema\Common\Protocol\DTO\Result; |
| 9 | use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 10 | |
| 11 | /** |
| 12 | * The client's response to an elicitation request. |
| 13 | * |
| 14 | * @since 2025-06-18 |
| 15 | * |
| 16 | * @mcp-domain Client |
| 17 | * @mcp-subdomain Elicitation |
| 18 | * @mcp-version 2025-11-25 |
| 19 | */ |
| 20 | class ElicitResult extends Result implements ClientResultInterface |
| 21 | { |
| 22 | use ValidatesRequiredFields; |
| 23 | |
| 24 | /** |
| 25 | * The user action in response to the elicitation. |
| 26 | * - "accept": User submitted the form/confirmed the action |
| 27 | * - "decline": User explicitly decline the action |
| 28 | * - "cancel": User dismissed without making an explicit choice |
| 29 | * |
| 30 | * @since 2025-06-18 |
| 31 | * |
| 32 | * @var 'accept'|'decline'|'cancel' |
| 33 | */ |
| 34 | protected string $action; |
| 35 | |
| 36 | /** |
| 37 | * The submitted form data, only present when action is "accept" and mode was "form". |
| 38 | * Contains values matching the requested schema. |
| 39 | * Omitted for out-of-band mode responses. |
| 40 | * |
| 41 | * @since 2025-06-18 |
| 42 | * |
| 43 | * @var array<string, string>|null |
| 44 | */ |
| 45 | protected ?array $content; |
| 46 | |
| 47 | /** |
| 48 | * @param 'accept'|'decline'|'cancel' $action @since 2025-06-18 |
| 49 | * @param array<string, mixed>|null $_meta @since 2025-06-18 |
| 50 | * @param array<string, string>|null $content @since 2025-06-18 |
| 51 | */ |
| 52 | public function __construct( |
| 53 | string $action, |
| 54 | ?array $_meta = null, |
| 55 | ?array $content = null |
| 56 | ) { |
| 57 | parent::__construct($_meta); |
| 58 | $this->action = $action; |
| 59 | $this->content = $content; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Creates an instance from an array. |
| 64 | * |
| 65 | * @param array{ |
| 66 | * _meta?: array<string, mixed>|null, |
| 67 | * action: 'accept'|'decline'|'cancel', |
| 68 | * content?: array<string, string>|null |
| 69 | * } $data |
| 70 | * @phpstan-param array<string, mixed> $data |
| 71 | * @return self |
| 72 | */ |
| 73 | public static function fromArray(array $data): self |
| 74 | { |
| 75 | self::assertRequired($data, ['action']); |
| 76 | |
| 77 | /** @var 'accept'|'decline'|'cancel' $action */ |
| 78 | $action = self::asString($data['action']); |
| 79 | |
| 80 | return new self( |
| 81 | $action, |
| 82 | self::asArrayOrNull($data['_meta'] ?? null), |
| 83 | self::asStringMapOrNull($data['content'] ?? null) |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Converts the instance to an array. |
| 89 | * |
| 90 | * @return array<string, mixed> |
| 91 | */ |
| 92 | public function toArray(): array |
| 93 | { |
| 94 | $result = parent::toArray(); |
| 95 | |
| 96 | $result['action'] = $this->action; |
| 97 | if ($this->content !== null) { |
| 98 | $result['content'] = $this->content; |
| 99 | } |
| 100 | |
| 101 | return $result; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @return 'accept'|'decline'|'cancel' |
| 106 | */ |
| 107 | public function getAction(): string |
| 108 | { |
| 109 | return $this->action; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @return array<string, string>|null |
| 114 | */ |
| 115 | public function getContent(): ?array |
| 116 | { |
| 117 | return $this->content; |
| 118 | } |
| 119 | } |
| 120 |