| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Schema\NotificationParams; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\MetaObject; |
| 18: | use Nexus\Mcp\Core\Schema\NotificationParams; |
| 19: | use Nexus\Mcp\Core\Schema\RequestId; |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | final readonly class CancelledNotificationParams extends NotificationParams |
| 27: | { |
| 28: | public function __construct( |
| 29: | public ?RequestId $requestId = null, |
| 30: | public ?string $reason = null, |
| 31: | MetaObject $meta = new MetaObject(), |
| 32: | ) { |
| 33: | parent::__construct($meta); |
| 34: | } |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | #[\Override] |
| 40: | public static function fromArray(array $data): static |
| 41: | { |
| 42: | $requestId = null; |
| 43: | |
| 44: | if (\array_key_exists('requestId', $data)) { |
| 45: | Assert::that($data['requestId'])->isArrayKey('"params.requestId" must be an int or string, {type} given.'); |
| 46: | $requestId = new RequestId($data['requestId']); |
| 47: | } |
| 48: | |
| 49: | $reason = $data['reason'] ?? null; |
| 50: | Assert::that($reason)->nullOr()->isString('"params.reason" must be a string or null, {type} given.'); |
| 51: | |
| 52: | $meta = new MetaObject(); |
| 53: | |
| 54: | if (\array_key_exists('_meta', $data)) { |
| 55: | Assert::that($data['_meta']) |
| 56: | ->isArray('"params._meta" must be an object, {type} given.') |
| 57: | ->isMap('"params._meta" must be a string-keyed object.') |
| 58: | ; |
| 59: | $meta = MetaObject::fromArray($data['_meta']); |
| 60: | } |
| 61: | |
| 62: | return new self($requestId, $reason, $meta); |
| 63: | } |
| 64: | |
| 65: | #[\Override] |
| 66: | public function toArray(): array |
| 67: | { |
| 68: | $data = parent::toArray(); |
| 69: | |
| 70: | if (null !== $this->requestId) { |
| 71: | $data['requestId'] = $this->requestId->id; |
| 72: | } |
| 73: | |
| 74: | if (null !== $this->reason) { |
| 75: | $data['reason'] = $this->reason; |
| 76: | } |
| 77: | |
| 78: | return $data; |
| 79: | } |
| 80: | |
| 81: | #[\Override] |
| 82: | public function jsonSerialize(): array |
| 83: | { |
| 84: | return $this->toArray(); |
| 85: | } |
| 86: | } |
| 87: | |