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