| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace WP\McpSchema\Client\Elicitation\DTO; |
| 6 |
|
| 7 |
use WP\McpSchema\Client\Elicitation\Union\PrimitiveSchemaDefinitionInterface; |
| 8 |
use WP\McpSchema\Common\AbstractDataTransferObject; |
| 9 |
use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 10 |
|
| 11 |
/** |
| 12 |
* @since 2025-06-18 |
| 13 |
* |
| 14 |
* @mcp-domain Client |
| 15 |
* @mcp-subdomain Elicitation |
| 16 |
* @mcp-version 2025-11-25 |
| 17 |
*/ |
| 18 |
class BooleanSchema extends AbstractDataTransferObject implements PrimitiveSchemaDefinitionInterface |
| 19 |
{ |
| 20 |
use ValidatesRequiredFields; |
| 21 |
|
| 22 |
public const TYPE = 'boolean'; |
| 23 |
|
| 24 |
public const DISCRIMINATOR_FIELD = 'type'; |
| 25 |
public const DISCRIMINATOR_VALUE = 'boolean'; |
| 26 |
|
| 27 |
/** |
| 28 |
* @since 2025-06-18 |
| 29 |
* |
| 30 |
* @var 'boolean' |
| 31 |
*/ |
| 32 |
protected string $type; |
| 33 |
|
| 34 |
/** |
| 35 |
* @since 2025-06-18 |
| 36 |
* |
| 37 |
* @var string|null |
| 38 |
*/ |
| 39 |
protected ?string $title; |
| 40 |
|
| 41 |
/** |
| 42 |
* @since 2025-06-18 |
| 43 |
* |
| 44 |
* @var string|null |
| 45 |
*/ |
| 46 |
protected ?string $description; |
| 47 |
|
| 48 |
/** |
| 49 |
* @since 2025-06-18 |
| 50 |
* |
| 51 |
* @var bool|null |
| 52 |
*/ |
| 53 |
protected ?bool $default; |
| 54 |
|
| 55 |
/** |
| 56 |
* @param string|null $title @since 2025-06-18 |
| 57 |
* @param string|null $description @since 2025-06-18 |
| 58 |
* @param bool|null $default @since 2025-06-18 |
| 59 |
*/ |
| 60 |
public function __construct( |
| 61 |
?string $title = null, |
| 62 |
?string $description = null, |
| 63 |
?bool $default = null |
| 64 |
) { |
| 65 |
$this->type = self::TYPE; |
| 66 |
$this->title = $title; |
| 67 |
$this->description = $description; |
| 68 |
$this->default = $default; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Creates an instance from an array. |
| 73 |
* |
| 74 |
* @param array{ |
| 75 |
* type: 'boolean', |
| 76 |
* title?: string|null, |
| 77 |
* description?: string|null, |
| 78 |
* default?: bool|null |
| 79 |
* } $data |
| 80 |
* @phpstan-param array<string, mixed> $data |
| 81 |
* @return self |
| 82 |
*/ |
| 83 |
public static function fromArray(array $data): self |
| 84 |
{ |
| 85 |
return new self( |
| 86 |
self::asStringOrNull($data['title'] ?? null), |
| 87 |
self::asStringOrNull($data['description'] ?? null), |
| 88 |
self::asBoolOrNull($data['default'] ?? null) |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Converts the instance to an array. |
| 94 |
* |
| 95 |
* @return array<string, mixed> |
| 96 |
*/ |
| 97 |
public function toArray(): array |
| 98 |
{ |
| 99 |
$result = []; |
| 100 |
|
| 101 |
$result['type'] = $this->type; |
| 102 |
if ($this->title !== null) { |
| 103 |
$result['title'] = $this->title; |
| 104 |
} |
| 105 |
if ($this->description !== null) { |
| 106 |
$result['description'] = $this->description; |
| 107 |
} |
| 108 |
if ($this->default !== null) { |
| 109 |
$result['default'] = $this->default; |
| 110 |
} |
| 111 |
|
| 112 |
return $result; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* @return 'boolean' |
| 117 |
*/ |
| 118 |
public function getType(): string |
| 119 |
{ |
| 120 |
return $this->type; |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* @return string|null |
| 125 |
*/ |
| 126 |
public function getTitle(): ?string |
| 127 |
{ |
| 128 |
return $this->title; |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* @return string|null |
| 133 |
*/ |
| 134 |
public function getDescription(): ?string |
| 135 |
{ |
| 136 |
return $this->description; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* @return bool|null |
| 141 |
*/ |
| 142 |
public function getDefault(): ?bool |
| 143 |
{ |
| 144 |
return $this->default; |
| 145 |
} |
| 146 |
} |
| 147 |
|