| 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\Enum\ResultType; |
| 18: | use Nexus\Mcp\Core\Schema\MetaObject; |
| 19: | use Nexus\Mcp\Core\Schema\MetaObject\GenericResultMetaObject; |
| 20: | use Nexus\Mcp\Core\Schema\MetaObject\ResultMetaObject; |
| 21: | use Nexus\Mcp\Core\Schema\Result; |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | final readonly class EmptyResult extends Result implements ClientResult, ServerResult |
| 34: | { |
| 35: | public function __construct(ResultMetaObject $meta = new GenericResultMetaObject()) |
| 36: | { |
| 37: | parent::__construct(meta: $meta); |
| 38: | } |
| 39: | |
| 40: | #[\Override] |
| 41: | public static function fromArray(array $data): static |
| 42: | { |
| 43: | $meta = new GenericResultMetaObject(); |
| 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 = GenericResultMetaObject::fromArray($data['_meta']); |
| 51: | } |
| 52: | |
| 53: | return new self(meta: $meta); |
| 54: | } |
| 55: | |
| 56: | #[\Override] |
| 57: | public function toArray(): array |
| 58: | { |
| 59: | $data = []; |
| 60: | $meta = $this->meta->toArray(); |
| 61: | |
| 62: | if ([] !== $meta) { |
| 63: | $data['_meta'] = $meta; |
| 64: | } |
| 65: | |
| 66: | $data['resultType'] = self::getResultType(); |
| 67: | |
| 68: | return $data; |
| 69: | } |
| 70: | |
| 71: | #[\Override] |
| 72: | public function rebuildWithMeta(ResultMetaObject $meta): static |
| 73: | { |
| 74: | return new self(meta: $meta); |
| 75: | } |
| 76: | |
| 77: | #[\Override] |
| 78: | protected function getResultType(): string |
| 79: | { |
| 80: | return ResultType::Complete->value; |
| 81: | } |
| 82: | } |
| 83: | |