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:
21: /**
22: * Parameters for a `notifications/resources/updated` notification.
23: *
24: * @extends NotificationParams<array{
25: * _meta?: template-type<MetaObject, Arrayable, 'T'>,
26: * uri: string,
27: * }>
28: *
29: * @see https://modelcontextprotocol.io/specification/draft/schema#resourceupdatednotificationparams
30: */
31: final readonly class ResourceUpdatedNotificationParams extends NotificationParams
32: {
33: public function __construct(public string $uri, MetaObject $meta = new MetaObject())
34: {
35: parent::__construct(meta: $meta);
36: }
37:
38: #[\Override]
39: public static function fromArray(array $data): static
40: {
41: Assert::that($data)->hasOffset('uri', '"params" is missing the required "uri" key.');
42: $uri = $data['uri'];
43: Assert::that($uri)->isString('"params.uri" must be a string, {type} given.');
44:
45: $meta = new MetaObject();
46:
47: if (\array_key_exists('_meta', $data)) {
48: Assert::that($data['_meta'])
49: ->isArray('"params._meta" must be an object, {type} given.')
50: ->isMap('"params._meta" must be a string-keyed object.')
51: ;
52: $meta = MetaObject::fromArray($data['_meta']);
53: }
54:
55: return new self(uri: $uri, meta: $meta);
56: }
57:
58: #[\Override]
59: public function toArray(): array
60: {
61: $data = [];
62: $meta = $this->meta->toArray();
63:
64: if ([] !== $meta) {
65: $data['_meta'] = $meta;
66: }
67:
68: $data['uri'] = $this->uri;
69:
70: return $data;
71: }
72:
73: #[\Override]
74: public function jsonSerialize(): array
75: {
76: return $this->toArray();
77: }
78: }
79: