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 / Common / Tasks / DTO / ListTasksResult.php

ListTasksResult.php in ZIP AI – AI Website Builder & AI Agent (Beta) 0.0.8, at lib/php-mcp-schema/src/Common/Tasks/DTO/ListTasksResult.php

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