| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Content; |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | final readonly class TextResourceContents extends ResourceContents |
| 27: | { |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | public function __construct( |
| 33: | string $uri, |
| 34: | public string $text, |
| 35: | ?string $mimeType = null, |
| 36: | ?array $meta = null, |
| 37: | ) { |
| 38: | if (preg_match('/[^\x09\x0A\x0D\x20-\x7E]/', $text) === 1) { |
| 39: | throw new \InvalidArgumentException('Text resource contents must have a valid non-binary string text.'); |
| 40: | } |
| 41: | |
| 42: | parent::__construct($uri, $mimeType, $meta); |
| 43: | } |
| 44: | |
| 45: | #[\Override] |
| 46: | public function toArray(): array |
| 47: | { |
| 48: | return array_filter([ |
| 49: | '_meta' => $this->meta, |
| 50: | 'uri' => $this->uri, |
| 51: | 'mimeType' => $this->mimeType, |
| 52: | 'text' => $this->text, |
| 53: | ], static fn(mixed $value): bool => null !== $value); |
| 54: | } |
| 55: | } |
| 56: | |