1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
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\NotificationParams;
20: use Nexus\Mcp\Core\Schema\SubscriptionFilter;
21:
22: /**
23: * Parameters for a `notifications/subscriptions/acknowledged` notification.
24: *
25: * @extends NotificationParams<array{
26: * _meta?: template-type<MetaObject, Arrayable, 'T'>,
27: * notifications: template-type<SubscriptionFilter, Arrayable, 'T'>,
28: * }>
29: *
30: * @see https://modelcontextprotocol.io/specification/draft/schema#subscriptionsacknowledgednotificationparams
31: */
32: final readonly class SubscriptionsAcknowledgedNotificationParams extends NotificationParams
33: {
34: public function __construct(public SubscriptionFilter $notifications, MetaObject $meta = new MetaObject())
35: {
36: parent::__construct(meta: $meta);
37: }
38:
39: #[\Override]
40: public static function fromArray(array $data): static
41: {
42: Assert::that($data)->hasOffset('notifications', '"params" is missing the required "notifications" key.');
43: Assert::that($data['notifications'])
44: ->isArray('"params.notifications" must be an object, {type} given.')
45: ->isMap('"params.notifications" must be a string-keyed object.')
46: ;
47: $notifications = SubscriptionFilter::fromArray($data['notifications']);
48:
49: $meta = new MetaObject();
50:
51: if (\array_key_exists('_meta', $data)) {
52: Assert::that($data['_meta'])
53: ->isArray('"params._meta" must be an object, {type} given.')
54: ->isMap('"params._meta" must be a string-keyed object.')
55: ;
56: $meta = MetaObject::fromArray($data['_meta']);
57: }
58:
59: return new self(notifications: $notifications, meta: $meta);
60: }
61:
62: #[\Override]
63: public function toArray(): array
64: {
65: $data = [];
66: $meta = $this->meta->toArray();
67:
68: if ([] !== $meta) {
69: $data['_meta'] = $meta;
70: }
71:
72: $data['notifications'] = $this->notifications->toArray();
73:
74: return $data;
75: }
76:
77: #[\Override]
78: public function jsonSerialize(): array
79: {
80: $data = $this->toArray();
81: $data['notifications'] = $this->notifications->jsonSerialize();
82:
83: return $data;
84: }
85: }
86: