| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Schema\Elicitation; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\Arrayable; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | final readonly class EnumOption implements Arrayable |
| 27: | { |
| 28: | |
| 29: | |
| 30: | |
| 31: | public string $const; |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | public string $title; |
| 37: | |
| 38: | public function __construct(string $const, string $title) |
| 39: | { |
| 40: | Assert::that($const)->isNonEmptyString('"oneOf.const" must be a non-empty string.'); |
| 41: | Assert::that($title)->isNonEmptyString('"oneOf.title" must be a non-empty string.'); |
| 42: | |
| 43: | $this->const = $const; |
| 44: | $this->title = $title; |
| 45: | } |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | #[\Override] |
| 51: | public static function fromArray(array $data): static |
| 52: | { |
| 53: | Assert::that($data)->hasOffset('const', '"oneOf" missing the required "const" key.'); |
| 54: | $const = $data['const']; |
| 55: | Assert::that($const)->isString('"oneOf.const" must be a string, {type} given.'); |
| 56: | |
| 57: | Assert::that($data)->hasOffset('title', '"oneOf" missing the required "title" key.'); |
| 58: | $title = $data['title']; |
| 59: | Assert::that($title)->isString('"oneOf.title" must be a string, {type} given.'); |
| 60: | |
| 61: | return new self($const, $title); |
| 62: | } |
| 63: | |
| 64: | #[\Override] |
| 65: | public function toArray(): array |
| 66: | { |
| 67: | return [ |
| 68: | 'const' => $this->const, |
| 69: | 'title' => $this->title, |
| 70: | ]; |
| 71: | } |
| 72: | |
| 73: | #[\Override] |
| 74: | public function jsonSerialize(): array |
| 75: | { |
| 76: | return $this->toArray(); |
| 77: | } |
| 78: | } |
| 79: | |