PluginProbe
ZIP AI – AI Website Builder & AI Agent / 0.0.13
ZIP AI – AI Website Builder & AI Agent v0.0.13
0.0.14 0.0.13 0.0.12 0.0.11 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 / Roots / DTO / ListRootsResult.php

ListRootsResult.php in ZIP AI – AI Website Builder & AI Agent 0.0.13, at lib/php-mcp-schema/src/Client/Roots/DTO/ListRootsResult.php

96 lines 2.4 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\Roots\DTO;
6
7 use WP\McpSchema\Client\Lifecycle\Union\ClientResultInterface;
8 use WP\McpSchema\Common\Protocol\DTO\Result;
9 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
10
11 /**
12 * The client's response to a roots/list request from the server.
13 * This result contains an array of Root objects, each representing a root directory
14 * or file that the server can operate on.
15 *
16 * @since 2024-11-05
17 * @last-updated 2025-11-25 (modified property: roots)
18 *
19 * @mcp-domain Client
20 * @mcp-subdomain Roots
21 * @mcp-version 2025-11-25
22 */
23 class ListRootsResult extends Result implements ClientResultInterface
24 {
25 use ValidatesRequiredFields;
26
27 /**
28 * @since 2024-11-05
29 *
30 * @var array<\WP\McpSchema\Client\Roots\DTO\Root>
31 */
32 protected array $roots;
33
34 /**
35 * @param array<\WP\McpSchema\Client\Roots\DTO\Root> $roots @since 2024-11-05
36 * @param array<string, mixed>|null $_meta @since 2024-11-05
37 */
38 public function __construct(
39 array $roots,
40 ?array $_meta = null
41 ) {
42 parent::__construct($_meta);
43 $this->roots = $roots;
44 }
45
46 /**
47 * Creates an instance from an array.
48 *
49 * @param array{
50 * _meta?: array<string, mixed>|null,
51 * roots: array<array<string, mixed>|\WP\McpSchema\Client\Roots\DTO\Root>
52 * } $data
53 * @phpstan-param array<string, mixed> $data
54 * @return self
55 */
56 public static function fromArray(array $data): self
57 {
58 self::assertRequired($data, ['roots']);
59
60 /** @var array<\WP\McpSchema\Client\Roots\DTO\Root> $roots */
61 $roots = array_map(
62 static fn($item) => is_array($item)
63 ? Root::fromArray($item)
64 : $item,
65 self::asArray($data['roots'])
66 );
67
68 return new self(
69 $roots,
70 self::asArrayOrNull($data['_meta'] ?? null)
71 );
72 }
73
74 /**
75 * Converts the instance to an array.
76 *
77 * @return array<string, mixed>
78 */
79 public function toArray(): array
80 {
81 $result = parent::toArray();
82
83 $result['roots'] = array_map(static fn($item) => $item->toArray(), $this->roots);
84
85 return $result;
86 }
87
88 /**
89 * @return array<\WP\McpSchema\Client\Roots\DTO\Root>
90 */
91 public function getRoots(): array
92 {
93 return $this->roots;
94 }
95 }
96