| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Schema; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | abstract readonly class BaseMetadata |
| 24: | { |
| 25: | |
| 26: | |
| 27: | |
| 28: | public string $name; |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | public ?string $title; |
| 34: | |
| 35: | public function __construct(string $name, ?string $title = null) |
| 36: | { |
| 37: | $label = basename(strtr(static::class, '\\', '/')); |
| 38: | |
| 39: | Assert::that($name)->isNonEmptyString(\sprintf('%s name must be a non-empty string.', $label)); |
| 40: | Assert::that($title)->nullOr()->isNonEmptyString(\sprintf('%s title must be a non-empty string or null.', $label)); |
| 41: | |
| 42: | $this->name = $name; |
| 43: | $this->title = $title; |
| 44: | } |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | public function getDisplayName(): string |
| 53: | { |
| 54: | return $this->title ?? $this->name; |
| 55: | } |
| 56: | } |
| 57: | |