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\Resource;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18: use Nexus\Mcp\Core\Schema\MetaObject\PayloadMetaObject;
19: use Nexus\Mcp\Core\Validation\Rfc3986UriValidator;
20:
21: /**
22: * The contents of a specific resource or sub-resource.
23: *
24: * @template T of array<string, mixed> = array<string, mixed>
25: *
26: * @implements Arrayable<T>
27: *
28: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2026-07-28/schema.ts
29: */
30: abstract readonly class ResourceContents implements Arrayable
31: {
32: /**
33: * @param non-empty-string $uri
34: * @param null|non-empty-string $mimeType
35: */
36: public function __construct(
37: public string $uri,
38: public ?string $mimeType = null,
39: public PayloadMetaObject $meta = new PayloadMetaObject(),
40: ) {
41: Rfc3986UriValidator::validate($uri, 'resource contents "uri"');
42: Assert::that($mimeType)->nullOr()->isNonEmptyString('resource contents "mimeType" must be a non-empty string or null.');
43: }
44:
45: #[\Override]
46: public function jsonSerialize(): array
47: {
48: return $this->toArray();
49: }
50: }
51: