| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Schema\Task; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\Arrayable; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | final readonly class TaskMetadata implements Arrayable |
| 29: | { |
| 30: | public function __construct(public ?int $ttl = null) |
| 31: | { |
| 32: | } |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | #[\Override] |
| 38: | public static function fromArray(array $data): static |
| 39: | { |
| 40: | $ttl = $data['ttl'] ?? null; |
| 41: | Assert::that($ttl)->nullOr()->isInt('task metadata "ttl" must be an int or null, {type} given.'); |
| 42: | |
| 43: | return new self($ttl); |
| 44: | } |
| 45: | |
| 46: | #[\Override] |
| 47: | public function toArray(): array |
| 48: | { |
| 49: | if (null === $this->ttl) { |
| 50: | return []; |
| 51: | } |
| 52: | |
| 53: | return ['ttl' => $this->ttl]; |
| 54: | } |
| 55: | |
| 56: | #[\Override] |
| 57: | public function jsonSerialize(): array|\stdClass |
| 58: | { |
| 59: | $data = $this->toArray(); |
| 60: | |
| 61: | return [] === $data ? new \stdClass() : $data; |
| 62: | } |
| 63: | } |
| 64: | |