| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | /** |
| 6: | * This file is part of the Nexus MCP SDK package. |
| 7: | * |
| 8: | * (c) 2025 John Paul E. Balandan, CPA <paulbalandan@gmail.com> |
| 9: | * |
| 10: | * For the full copyright and license information, please view |
| 11: | * the LICENSE file that was distributed with this source code. |
| 12: | */ |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Elicitation; |
| 15: | |
| 16: | /** |
| 17: | * @implements PrimitiveSchemaDefinition<array{ |
| 18: | * type: 'boolean', |
| 19: | * description?: non-empty-string, |
| 20: | * title?: non-empty-string, |
| 21: | * default?: bool, |
| 22: | * }> |
| 23: | */ |
| 24: | final readonly class BooleanSchema implements PrimitiveSchemaDefinition |
| 25: | { |
| 26: | /** |
| 27: | * @var non-empty-string |
| 28: | */ |
| 29: | public string $type; |
| 30: | |
| 31: | /** |
| 32: | * @param null|non-empty-string $description |
| 33: | * @param null|non-empty-string $title |
| 34: | */ |
| 35: | public function __construct( |
| 36: | public ?string $description = null, |
| 37: | public ?string $title = null, |
| 38: | public ?bool $default = null, |
| 39: | ) { |
| 40: | $this->type = 'boolean'; |
| 41: | } |
| 42: | |
| 43: | #[\Override] |
| 44: | public function toArray(): array |
| 45: | { |
| 46: | return array_filter([ |
| 47: | 'type' => $this->type, |
| 48: | 'description' => $this->description, |
| 49: | 'title' => $this->title, |
| 50: | 'default' => $this->default, |
| 51: | ], static fn(mixed $value): bool => null !== $value); |
| 52: | } |
| 53: | |
| 54: | /** |
| 55: | * @return template-type<self, PrimitiveSchemaDefinition, 'T'> |
| 56: | */ |
| 57: | #[\Override] |
| 58: | public function jsonSerialize(): array |
| 59: | { |
| 60: | return $this->toArray(); |
| 61: | } |
| 62: | } |
| 63: |