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