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 / Factory / ElicitRequestParamsFactory.php

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

80 lines 2.1 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\Factory;
6
7 use WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface;
8 use WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParams;
9 use WP\McpSchema\Client\Elicitation\DTO\ElicitRequestURLParams;
10
11 /**
12 * Factory for creating ElicitRequestParams union type instances.
13 *
14 * The parameters for a request to elicit additional information from the user via the client.
15 *
16 * @mcp-domain Client
17 * @mcp-subdomain Elicitation
18 * @mcp-version 2025-11-25
19 */
20 final class ElicitRequestParamsFactory
21 {
22 /**
23 * Registry mapping discriminator values to implementation classes.
24 *
25 * @var array<string, class-string<ElicitRequestParamsInterface>>
26 */
27 public const REGISTRY = [
28 'form' => ElicitRequestFormParams::class,
29 'url' => ElicitRequestURLParams::class,
30 ];
31
32 /**
33 * Creates an instance from an array.
34 *
35 * @param array<string, mixed> $data
36 * @return ElicitRequestParamsInterface
37 * @throws \InvalidArgumentException
38 */
39 public static function fromArray(array $data): ElicitRequestParamsInterface
40 {
41 if (!isset($data['mode'])) {
42 throw new \InvalidArgumentException('Missing discriminator field: mode');
43 }
44
45 /** @var string $mode */
46 $mode = $data['mode'];
47 if (!isset(self::REGISTRY[$mode])) {
48 throw new \InvalidArgumentException(sprintf(
49 "Unknown mode value '%s'. Valid values: %s",
50 $mode,
51 implode(', ', array_keys(self::REGISTRY))
52 ));
53 }
54
55 $class = self::REGISTRY[$mode];
56 return $class::fromArray($data);
57 }
58
59 /**
60 * Checks if a mode value is supported by this factory.
61 *
62 * @param string $mode
63 * @return bool
64 */
65 public static function supports(string $mode): bool
66 {
67 return isset(self::REGISTRY[$mode]);
68 }
69
70 /**
71 * Returns all supported mode values.
72 *
73 * @return array<string>
74 */
75 public static function modes(): array
76 {
77 return array_keys(self::REGISTRY);
78 }
79 }
80