| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | /** |
| 6: | * This file is part of the Nexus MCP SDK package. |
| 7: | * |
| 8: | * (c) 2025 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\Schema; |
| 15: | |
| 16: | /** |
| 17: | * An optionally-sized icon that can be displayed in a user interface. |
| 18: | * |
| 19: | * @implements Arrayable<array{ |
| 20: | * src: non-empty-string, |
| 21: | * mimeType?: non-empty-string, |
| 22: | * sizes?: list<non-empty-string>, |
| 23: | * theme?: 'dark'|'light', |
| 24: | * }> |
| 25: | */ |
| 26: | final readonly class Icon implements \JsonSerializable, Arrayable |
| 27: | { |
| 28: | /** |
| 29: | * @param non-empty-string $src A standard URI pointing to an icon resource. |
| 30: | * @param null|non-empty-string $mimeType Optional MIME type override if the source MIME type is missing or generic. |
| 31: | * @param null|list<non-empty-string> $sizes Optional array of strings that specify sizes at which the icon can be used. |
| 32: | * @param null|'dark'|'light' $theme Optional specifier for the theme this icon is designed for. |
| 33: | */ |
| 34: | public function __construct( |
| 35: | public string $src, |
| 36: | public ?string $mimeType = null, |
| 37: | public ?array $sizes = null, |
| 38: | public ?string $theme = null, |
| 39: | ) {} |
| 40: | |
| 41: | #[\Override] |
| 42: | public function toArray(): array |
| 43: | { |
| 44: | return array_filter([ |
| 45: | 'src' => $this->src, |
| 46: | 'mimeType' => $this->mimeType, |
| 47: | 'sizes' => $this->sizes, |
| 48: | 'theme' => $this->theme, |
| 49: | ], static fn(mixed $value): bool => null !== $value); |
| 50: | } |
| 51: | |
| 52: | /** |
| 53: | * @return template-type<self, Arrayable, 'T'> |
| 54: | */ |
| 55: | #[\Override] |
| 56: | public function jsonSerialize(): array |
| 57: | { |
| 58: | return $this->toArray(); |
| 59: | } |
| 60: | } |
| 61: |