-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathBooleanSchemaDefinition.php
More file actions
70 lines (62 loc) · 1.72 KB
/
BooleanSchemaDefinition.php
File metadata and controls
70 lines (62 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Schema\Elicitation;
/**
* Schema definition for boolean fields in elicitation requests.
*
* @author Johannes Wachter <johannes@sulu.io>
*/
final class BooleanSchemaDefinition extends AbstractSchemaDefinition
{
/**
* @param string $title Human-readable title for the field
* @param string|null $description Optional description/help text
* @param bool|null $default Optional default value
*/
public function __construct(
string $title,
?string $description = null,
public readonly ?bool $default = null,
) {
parent::__construct($title, $description);
}
/**
* @param array{
* title: string,
* description?: string,
* default?: bool,
* } $data
*/
public static function fromArray(array $data): self
{
self::validateTitle($data, 'boolean');
return new self(
title: $data['title'],
description: $data['description'] ?? null,
default: isset($data['default']) ? (bool) $data['default'] : null,
);
}
/**
* @return array{
* type: string,
* title: string,
* description?: string,
* default?: bool,
* }
*/
public function jsonSerialize(): array
{
$data = $this->buildBaseJson('boolean');
if (null !== $this->default) {
$data['default'] = $this->default;
}
return $data;
}
}