| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace WP\McpSchema\Server\Resources\DTO; |
| 6 |
|
| 7 |
use WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta; |
| 8 |
use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 9 |
|
| 10 |
/** |
| 11 |
* Parameters for a `resources/subscribe` request. |
| 12 |
* |
| 13 |
* Note: This class is structurally identical to ResourceRequestParams. |
| 14 |
* It exists as a separate type for semantic distinction per MCP specification. |
| 15 |
* |
| 16 |
* @since 2025-11-25 |
| 17 |
* |
| 18 |
* @mcp-domain Server |
| 19 |
* @mcp-subdomain Resources |
| 20 |
* @mcp-version 2025-11-25 |
| 21 |
* @see ResourceRequestParams |
| 22 |
*/ |
| 23 |
class SubscribeRequestParams extends ResourceRequestParams |
| 24 |
{ |
| 25 |
use ValidatesRequiredFields; |
| 26 |
|
| 27 |
/** |
| 28 |
* @param string $uri @since 2025-11-25 |
| 29 |
* @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta @since 2025-11-25 |
| 30 |
*/ |
| 31 |
public function __construct( |
| 32 |
string $uri, |
| 33 |
?RequestParamsMeta $_meta = null |
| 34 |
) { |
| 35 |
parent::__construct($uri, $_meta); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Creates an instance from an array. |
| 40 |
* |
| 41 |
* @param array{ |
| 42 |
* uri: string, |
| 43 |
* _meta?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null |
| 44 |
* } $data |
| 45 |
* @phpstan-param array<string, mixed> $data |
| 46 |
* @return self |
| 47 |
*/ |
| 48 |
public static function fromArray(array $data): self |
| 49 |
{ |
| 50 |
self::assertRequired($data, ['uri']); |
| 51 |
|
| 52 |
/** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */ |
| 53 |
$_meta = isset($data['_meta']) |
| 54 |
? (is_array($data['_meta']) |
| 55 |
? RequestParamsMeta::fromArray(self::asArray($data['_meta'])) |
| 56 |
: $data['_meta']) |
| 57 |
: null; |
| 58 |
|
| 59 |
return new self( |
| 60 |
self::asString($data['uri']), |
| 61 |
$_meta |
| 62 |
); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Converts the instance to an array. |
| 67 |
* |
| 68 |
* @return array<string, mixed> |
| 69 |
*/ |
| 70 |
public function toArray(): array |
| 71 |
{ |
| 72 |
$result = parent::toArray(); |
| 73 |
|
| 74 |
return $result; |
| 75 |
} |
| 76 |
} |
| 77 |
|