| 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\Arrayable; |
| 18: | use Nexus\Mcp\Core\Schema\MetaObject; |
| 19: | use Nexus\Mcp\Core\Schema\MetaObject\NotificationMetaObject; |
| 20: | use Nexus\Mcp\Core\Schema\NotificationParams; |
| 21: | use Nexus\Mcp\Core\Schema\SubscriptionFilter; |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | final readonly class SubscriptionsAcknowledgedNotificationParams extends NotificationParams |
| 34: | { |
| 35: | public function __construct(public SubscriptionFilter $notifications, NotificationMetaObject $meta = new NotificationMetaObject()) |
| 36: | { |
| 37: | parent::__construct(meta: $meta); |
| 38: | } |
| 39: | |
| 40: | #[\Override] |
| 41: | public static function fromArray(array $data): static |
| 42: | { |
| 43: | Assert::that($data)->hasOffset('notifications', '"params" is missing the required "notifications" key.'); |
| 44: | Assert::that($data['notifications']) |
| 45: | ->isArray('"params.notifications" must be an object, {type} given.') |
| 46: | ->isMap('"params.notifications" must be a string-keyed object.') |
| 47: | ; |
| 48: | $notifications = SubscriptionFilter::fromArray($data['notifications']); |
| 49: | |
| 50: | $meta = new NotificationMetaObject(); |
| 51: | |
| 52: | if (\array_key_exists('_meta', $data)) { |
| 53: | Assert::that($data['_meta']) |
| 54: | ->isArray('"params._meta" must be an object, {type} given.') |
| 55: | ->isMap('"params._meta" must be a string-keyed object.') |
| 56: | ; |
| 57: | $meta = NotificationMetaObject::fromArray($data['_meta']); |
| 58: | } |
| 59: | |
| 60: | return new self(notifications: $notifications, meta: $meta); |
| 61: | } |
| 62: | |
| 63: | #[\Override] |
| 64: | public function toArray(): array |
| 65: | { |
| 66: | $data = []; |
| 67: | $meta = $this->meta->toArray(); |
| 68: | |
| 69: | if ([] !== $meta) { |
| 70: | $data['_meta'] = $meta; |
| 71: | } |
| 72: | |
| 73: | $data['notifications'] = $this->notifications->toArray(); |
| 74: | |
| 75: | return $data; |
| 76: | } |
| 77: | |
| 78: | #[\Override] |
| 79: | public function jsonSerialize(): array |
| 80: | { |
| 81: | $data = $this->toArray(); |
| 82: | $data['notifications'] = $this->notifications->jsonSerialize(); |
| 83: | |
| 84: | return $data; |
| 85: | } |
| 86: | } |
| 87: | |