PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.2
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.2
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / wordpress / php-mcp-schema / src / Client / Elicitation / DTO / ElicitResult.php

ElicitResult.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.3.2, at vendor/wordpress/php-mcp-schema/src/Client/Elicitation/DTO/ElicitResult.php

120 lines 2.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\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