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 / MultiSelectEnumSchemaFactory.php

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

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