PluginProbe
ZIP AI – AI Website Builder & AI Agent (Beta) / 0.0.8
ZIP AI – AI Website Builder & AI Agent (Beta) v0.0.8
0.0.10 0.0.9 trunk 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8
zip-ai / lib / php-mcp-schema / src / Client / Elicitation / DTO / NumberSchema.php

NumberSchema.php in ZIP AI – AI Website Builder & AI Agent (Beta) 0.0.8, at lib/php-mcp-schema/src/Client/Elicitation/DTO/NumberSchema.php

197 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * @last-updated 2025-11-25 (added properties: default)
14 *
15 * @mcp-domain Client
16 * @mcp-subdomain Elicitation
17 * @mcp-version 2025-11-25
18 */
19 class NumberSchema extends AbstractDataTransferObject implements PrimitiveSchemaDefinitionInterface
20 {
21 use ValidatesRequiredFields;
22
23 /**
24 * @since 2025-06-18
25 *
26 * @var 'number'|'integer'
27 */
28 protected string $type;
29
30 /**
31 * @since 2025-06-18
32 *
33 * @var string|null
34 */
35 protected ?string $title;
36
37 /**
38 * @since 2025-06-18
39 *
40 * @var string|null
41 */
42 protected ?string $description;
43
44 /**
45 * @since 2025-06-18
46 *
47 * @var float|null
48 */
49 protected ?float $minimum;
50
51 /**
52 * @since 2025-06-18
53 *
54 * @var float|null
55 */
56 protected ?float $maximum;
57
58 /**
59 * @since 2025-11-25
60 *
61 * @var float|null
62 */
63 protected ?float $default;
64
65 /**
66 * @param 'number'|'integer' $type @since 2025-06-18
67 * @param string|null $title @since 2025-06-18
68 * @param string|null $description @since 2025-06-18
69 * @param float|null $minimum @since 2025-06-18
70 * @param float|null $maximum @since 2025-06-18
71 * @param float|null $default @since 2025-11-25
72 */
73 public function __construct(
74 string $type,
75 ?string $title = null,
76 ?string $description = null,
77 ?float $minimum = null,
78 ?float $maximum = null,
79 ?float $default = null
80 ) {
81 $this->type = $type;
82 $this->title = $title;
83 $this->description = $description;
84 $this->minimum = $minimum;
85 $this->maximum = $maximum;
86 $this->default = $default;
87 }
88
89 /**
90 * Creates an instance from an array.
91 *
92 * @param array{
93 * type: 'number'|'integer',
94 * title?: string|null,
95 * description?: string|null,
96 * minimum?: float|null,
97 * maximum?: float|null,
98 * default?: float|null
99 * } $data
100 * @phpstan-param array<string, mixed> $data
101 * @return self
102 */
103 public static function fromArray(array $data): self
104 {
105 self::assertRequired($data, ['type']);
106
107 /** @var 'number'|'integer' $type */
108 $type = self::asString($data['type']);
109
110 return new self(
111 $type,
112 self::asStringOrNull($data['title'] ?? null),
113 self::asStringOrNull($data['description'] ?? null),
114 self::asFloatOrNull($data['minimum'] ?? null),
115 self::asFloatOrNull($data['maximum'] ?? null),
116 self::asFloatOrNull($data['default'] ?? null)
117 );
118 }
119
120 /**
121 * Converts the instance to an array.
122 *
123 * @return array<string, mixed>
124 */
125 public function toArray(): array
126 {
127 $result = [];
128
129 $result['type'] = $this->type;
130 if ($this->title !== null) {
131 $result['title'] = $this->title;
132 }
133 if ($this->description !== null) {
134 $result['description'] = $this->description;
135 }
136 if ($this->minimum !== null) {
137 $result['minimum'] = $this->minimum;
138 }
139 if ($this->maximum !== null) {
140 $result['maximum'] = $this->maximum;
141 }
142 if ($this->default !== null) {
143 $result['default'] = $this->default;
144 }
145
146 return $result;
147 }
148
149 /**
150 * @return 'number'|'integer'
151 */
152 public function getType(): string
153 {
154 return $this->type;
155 }
156
157 /**
158 * @return string|null
159 */
160 public function getTitle(): ?string
161 {
162 return $this->title;
163 }
164
165 /**
166 * @return string|null
167 */
168 public function getDescription(): ?string
169 {
170 return $this->description;
171 }
172
173 /**
174 * @return float|null
175 */
176 public function getMinimum(): ?float
177 {
178 return $this->minimum;
179 }
180
181 /**
182 * @return float|null
183 */
184 public function getMaximum(): ?float
185 {
186 return $this->maximum;
187 }
188
189 /**
190 * @return float|null
191 */
192 public function getDefault(): ?float
193 {
194 return $this->default;
195 }
196 }
197