convertkit
/
vendor
/
wordpress
/
php-mcp-schema
/
src
/
Common
/
Protocol
/
DTO
/
PaginatedRequest.php
PaginatedRequest.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.3, at vendor/wordpress/php-mcp-schema/src/Common/Protocol/DTO/PaginatedRequest.php
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WP\McpSchema\Common\Protocol\DTO; |
| 6 | |
| 7 | use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest; |
| 8 | use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 9 | |
| 10 | /** |
| 11 | * @since 2024-11-05 |
| 12 | * @last-updated 2025-11-25 (modified property: params) |
| 13 | * |
| 14 | * @mcp-domain Common |
| 15 | * @mcp-subdomain Protocol |
| 16 | * @mcp-version 2025-11-25 |
| 17 | */ |
| 18 | class PaginatedRequest extends JSONRPCRequest |
| 19 | { |
| 20 | use ValidatesRequiredFields; |
| 21 | |
| 22 | /** |
| 23 | * @var \WP\McpSchema\Common\Protocol\DTO\PaginatedRequestParams|null |
| 24 | */ |
| 25 | protected ?PaginatedRequestParams $typedParams; |
| 26 | |
| 27 | /** |
| 28 | * @param '2.0' $jsonrpc @since 2025-11-25 |
| 29 | * @param string|number $id @since 2025-11-25 |
| 30 | * @param string $method @since 2024-11-05 |
| 31 | * @param \WP\McpSchema\Common\Protocol\DTO\PaginatedRequestParams|null $params @since 2024-11-05 |
| 32 | */ |
| 33 | public function __construct( |
| 34 | string $jsonrpc, |
| 35 | $id, |
| 36 | string $method, |
| 37 | ?PaginatedRequestParams $params = null |
| 38 | ) { |
| 39 | parent::__construct($method, $jsonrpc, $id, null); |
| 40 | $this->typedParams = $params; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Creates an instance from an array. |
| 45 | * |
| 46 | * @param array{ |
| 47 | * jsonrpc: '2.0', |
| 48 | * id: string|number, |
| 49 | * method: string, |
| 50 | * params?: array<string, mixed>|\WP\McpSchema\Common\Protocol\DTO\PaginatedRequestParams|null |
| 51 | * } $data |
| 52 | * @phpstan-param array<string, mixed> $data |
| 53 | * @return self |
| 54 | */ |
| 55 | public static function fromArray(array $data): self |
| 56 | { |
| 57 | self::assertRequired($data, ['jsonrpc', 'id', 'method']); |
| 58 | |
| 59 | /** @var '2.0' $jsonrpc */ |
| 60 | $jsonrpc = self::asString($data['jsonrpc']); |
| 61 | |
| 62 | /** @var string|number $id */ |
| 63 | $id = self::asStringOrNumber($data['id']); |
| 64 | |
| 65 | /** @var \WP\McpSchema\Common\Protocol\DTO\PaginatedRequestParams|null $params */ |
| 66 | $params = isset($data['params']) |
| 67 | ? (is_array($data['params']) |
| 68 | ? PaginatedRequestParams::fromArray(self::asArray($data['params'])) |
| 69 | : $data['params']) |
| 70 | : null; |
| 71 | |
| 72 | return new self( |
| 73 | $jsonrpc, |
| 74 | $id, |
| 75 | self::asString($data['method']), |
| 76 | $params |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Converts the instance to an array. |
| 82 | * |
| 83 | * @return array<string, mixed> |
| 84 | */ |
| 85 | public function toArray(): array |
| 86 | { |
| 87 | $result = parent::toArray(); |
| 88 | |
| 89 | if ($this->typedParams !== null) { |
| 90 | $result['params'] = $this->typedParams->toArray(); |
| 91 | } |
| 92 | |
| 93 | return $result; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @return \WP\McpSchema\Common\Protocol\DTO\PaginatedRequestParams|null |
| 98 | */ |
| 99 | public function getTypedParams(): ?PaginatedRequestParams |
| 100 | { |
| 101 | return $this->typedParams; |
| 102 | } |
| 103 | } |
| 104 |