| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Schema\RequestParams; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\RequestMetaObject; |
| 18: | use Nexus\Mcp\Core\Schema\RequestParams; |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | final readonly class GetTaskRequestParams extends RequestParams |
| 26: | { |
| 27: | public function __construct(public string $taskId, RequestMetaObject $meta = new RequestMetaObject()) |
| 28: | { |
| 29: | parent::__construct($meta); |
| 30: | } |
| 31: | |
| 32: | #[\Override] |
| 33: | public static function fromArray(array $data): static |
| 34: | { |
| 35: | Assert::that($data)->hasOffset('taskId', 'missing the required "taskId" key.'); |
| 36: | $taskId = $data['taskId']; |
| 37: | Assert::that($taskId)->isString('"params.taskId" must be a string, {type} given.'); |
| 38: | |
| 39: | $meta = new RequestMetaObject(); |
| 40: | |
| 41: | if (\array_key_exists('_meta', $data)) { |
| 42: | Assert::that($data['_meta']) |
| 43: | ->isArray('"params._meta" must be an object, {type} given.') |
| 44: | ->isMap('"params._meta" must be a string-keyed object.') |
| 45: | ; |
| 46: | $meta = RequestMetaObject::fromArray($data['_meta']); |
| 47: | } |
| 48: | |
| 49: | return new self($taskId, $meta); |
| 50: | } |
| 51: | |
| 52: | #[\Override] |
| 53: | public function toArray(): array |
| 54: | { |
| 55: | return [ |
| 56: | ...parent::toArray(), |
| 57: | 'taskId' => $this->taskId, |
| 58: | ]; |
| 59: | } |
| 60: | |
| 61: | #[\Override] |
| 62: | public function jsonSerialize(): array |
| 63: | { |
| 64: | return $this->toArray(); |
| 65: | } |
| 66: | } |
| 67: | |