| 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: | |
| 35: | |
| 36: | public function __construct( |
| 37: | public string $message, |
| 38: | public string $mode, |
| 39: | public string $url, |
| 40: | ) { |
| 41: | Assert::that($message)->isNonEmptyString('"params.message" must be a non-empty string.'); |
| 42: | Assert::that($url)->isNonEmptyString('"params.url" must be a non-empty string.')->isUrl('"params.url" must be a valid URL.'); |
| 43: | Assert::that($mode)->isIdentical(self::MODE, '"params.mode" must be {other}, {value} given.'); |
| 44: | } |
| 45: | |
| 46: | #[\Override] |
| 47: | public static function fromArray(array $data): static |
| 48: | { |
| 49: | Assert::that($data)->hasOffset('message', '"params" is missing the required "message" key.'); |
| 50: | $message = $data['message']; |
| 51: | Assert::that($message)->isNonEmptyString('"params.message" must be a non-empty string, {type} given.'); |
| 52: | |
| 53: | Assert::that($data)->hasOffset('mode', '"params" is missing the required "mode" key.'); |
| 54: | $mode = $data['mode']; |
| 55: | Assert::that($mode)->isIdentical(self::MODE, '"params.mode" must be {other}, {value} given.'); |
| 56: | |
| 57: | Assert::that($data)->hasOffset('url', '"params" is missing the required "url" key.'); |
| 58: | $url = $data['url']; |
| 59: | Assert::that($url)->isNonEmptyString('"params.url" must be a non-empty string, {type} given.'); |
| 60: | |
| 61: | return new self(message: $message, mode: $mode, url: $url); |
| 62: | } |
| 63: | |
| 64: | #[\Override] |
| 65: | public function toArray(): array |
| 66: | { |
| 67: | return [ |
| 68: | 'message' => $this->message, |
| 69: | 'mode' => $this->mode, |
| 70: | 'url' => $this->url, |
| 71: | ]; |
| 72: | } |
| 73: | |
| 74: | #[\Override] |
| 75: | public function jsonSerialize(): array |
| 76: | { |
| 77: | return $this->toArray(); |
| 78: | } |
| 79: | } |
| 80: | |