1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 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\Core\Schema;
15:
16: /**
17: * Interface for classes that can be converted to and from arrays.
18: *
19: * @template-covariant T of array<array-key, mixed> = array<string, mixed>
20: */
21: interface Arrayable extends \JsonSerializable
22: {
23: /**
24: * @template TData of array<string, mixed>
25: *
26: * @param TData $data
27: *
28: * @todo See ROADMAP.md (PHP 8.5 language compatibility).
29: */
30: public static function fromArray(array $data): static;
31:
32: /**
33: * @return T
34: */
35: public function toArray(): array;
36:
37: /**
38: * Implementations substitute `\stdClass` for the empty-object case so
39: * `json_encode` emits `{}` rather than `[]`.
40: *
41: * @return array<string, mixed>|\stdClass
42: */
43: #[\Override]
44: public function jsonSerialize(): array|\stdClass;
45: }
46: