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