| 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 BlobResourceContents extends ResourceContents |
| 27: | { |
| 28: | |
| 29: | |
| 30: | |
| 31: | public function __construct( |
| 32: | string $uri, |
| 33: | public string $blob, |
| 34: | ?string $mimeType = null, |
| 35: | ?array $meta = null, |
| 36: | ) { |
| 37: | if (base64_encode((string) base64_decode($blob, true)) !== $blob) { |
| 38: | throw new \InvalidArgumentException('Blob resource contents must have a valid base64-encoded blob.'); |
| 39: | } |
| 40: | |
| 41: | parent::__construct($uri, $mimeType, $meta); |
| 42: | } |
| 43: | |
| 44: | #[\Override] |
| 45: | public function toArray(): array |
| 46: | { |
| 47: | return array_filter([ |
| 48: | '_meta' => $this->meta, |
| 49: | 'uri' => $this->uri, |
| 50: | 'mimeType' => $this->mimeType, |
| 51: | 'blob' => $this->blob, |
| 52: | ], static fn(mixed $value): bool => null !== $value); |
| 53: | } |
| 54: | } |
| 55: | |