| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Extension\Skills\Schema\RequestParams; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\Cursor; |
| 18: | use Nexus\Mcp\Core\Schema\MetaObject; |
| 19: | use Nexus\Mcp\Core\Schema\MetaObject\RequestMetaObject; |
| 20: | use Nexus\Mcp\Core\Schema\RequestParams; |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | final readonly class ReadResourceDirectoryRequestParams extends RequestParams |
| 34: | { |
| 35: | |
| 36: | |
| 37: | |
| 38: | public function __construct( |
| 39: | public string $uri, |
| 40: | RequestMetaObject $meta, |
| 41: | public ?Cursor $cursor = null, |
| 42: | ) { |
| 43: | Assert::that($uri)->isNonEmptyString('"params.uri" must be a non-empty string.'); |
| 44: | |
| 45: | parent::__construct(meta: $meta); |
| 46: | } |
| 47: | |
| 48: | #[\Override] |
| 49: | public static function fromArray(array $data): static |
| 50: | { |
| 51: | Assert::that($data)->hasOffset('uri', '"params" is missing the required "uri" key.'); |
| 52: | $uri = $data['uri']; |
| 53: | Assert::that($uri)->isNonEmptyString('"params.uri" must be a non-empty string, {type} given.'); |
| 54: | |
| 55: | $cursor = null; |
| 56: | |
| 57: | if (\array_key_exists('cursor', $data)) { |
| 58: | $raw = $data['cursor']; |
| 59: | Assert::that($raw)->isNonEmptyString('"params.cursor" must be a non-empty string, {type} given.'); |
| 60: | $cursor = new Cursor(cursor: $raw); |
| 61: | } |
| 62: | |
| 63: | Assert::that($data)->hasOffset('_meta', '"params" is missing the required "_meta" key.'); |
| 64: | Assert::that($data['_meta']) |
| 65: | ->isArray('"params._meta" must be an object, {type} given.') |
| 66: | ->not()->isNonEmptyList('"params._meta" must be a string-keyed object.') |
| 67: | ; |
| 68: | |
| 69: | return new self(uri: $uri, meta: RequestMetaObject::fromArray($data['_meta']), cursor: $cursor); |
| 70: | } |
| 71: | |
| 72: | #[\Override] |
| 73: | public function toArray(): array |
| 74: | { |
| 75: | $data = [ |
| 76: | '_meta' => $this->meta->toArray(), |
| 77: | 'uri' => $this->uri, |
| 78: | ]; |
| 79: | |
| 80: | if (null !== $this->cursor) { |
| 81: | $data['cursor'] = $this->cursor->cursor; |
| 82: | } |
| 83: | |
| 84: | return $data; |
| 85: | } |
| 86: | } |
| 87: | |