| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Schema\Request; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcRequest; |
| 18: | use Nexus\Mcp\Core\Schema\RequestId; |
| 19: | use Nexus\Mcp\Core\Schema\RequestParams; |
| 20: | use Nexus\Mcp\Core\Schema\RequestParams\SubscriptionsListenRequestParams; |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | final readonly class SubscriptionsListenRequest extends JsonRpcRequest implements ClientRequest |
| 39: | { |
| 40: | public function __construct(RequestId $id, SubscriptionsListenRequestParams $params) |
| 41: | { |
| 42: | parent::__construct(id: $id, params: $params); |
| 43: | } |
| 44: | |
| 45: | #[\Override] |
| 46: | public static function getMethod(): string |
| 47: | { |
| 48: | return 'subscriptions/listen'; |
| 49: | } |
| 50: | |
| 51: | #[\Override] |
| 52: | public static function fromArray(array $data): static |
| 53: | { |
| 54: | Assert::that($data)->hasOffset('id', 'missing the required "id" key.'); |
| 55: | $id = $data['id']; |
| 56: | Assert::that($id)->isArrayKey('"id" must be an int or string, {type} given.'); |
| 57: | |
| 58: | Assert::that($data)->hasOffset('params', 'missing the required "params" key.'); |
| 59: | Assert::that($data['params']) |
| 60: | ->isArray('"params" must be an object, {type} given.') |
| 61: | ->isMap('"params" must be a string-keyed object.') |
| 62: | ; |
| 63: | |
| 64: | return new self( |
| 65: | id: new RequestId(id: $id), |
| 66: | params: SubscriptionsListenRequestParams::fromArray($data['params']), |
| 67: | ); |
| 68: | } |
| 69: | |
| 70: | #[\Override] |
| 71: | public function toArray(): array |
| 72: | { |
| 73: | return [ |
| 74: | 'jsonrpc' => self::JSONRPC_VERSION, |
| 75: | 'id' => $this->id->id, |
| 76: | 'method' => static::getMethod(), |
| 77: | 'params' => $this->params->toArray(), |
| 78: | ]; |
| 79: | } |
| 80: | } |
| 81: | |