ref = $ref; $this->argument = $argument; $this->context = $context; } /** * Creates an instance from an array. * * @param array{ * _meta?: array|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null, * ref: \WP\McpSchema\Server\Core\DTO\PromptReference|\WP\McpSchema\Server\Core\DTO\ResourceTemplateReference, * argument: array|\WP\McpSchema\Server\Core\DTO\CompleteRequestParamsArgument, * context?: array|\WP\McpSchema\Server\Core\DTO\CompleteRequestParamsContext|null * } $data * @phpstan-param array $data * @return self */ public static function fromArray(array $data): self { self::assertRequired($data, ['ref', 'argument']); /** @var \WP\McpSchema\Server\Core\DTO\PromptReference|\WP\McpSchema\Server\Core\DTO\ResourceTemplateReference $ref */ $ref = $data['ref']; /** @var \WP\McpSchema\Server\Core\DTO\CompleteRequestParamsArgument $argument */ $argument = is_array($data['argument']) ? CompleteRequestParamsArgument::fromArray(self::asArray($data['argument'])) : $data['argument']; /** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */ $_meta = isset($data['_meta']) ? (is_array($data['_meta']) ? RequestParamsMeta::fromArray(self::asArray($data['_meta'])) : $data['_meta']) : null; /** @var \WP\McpSchema\Server\Core\DTO\CompleteRequestParamsContext|null $context */ $context = isset($data['context']) ? (is_array($data['context']) ? CompleteRequestParamsContext::fromArray(self::asArray($data['context'])) : $data['context']) : null; return new self( $ref, $argument, $_meta, $context ); } /** * Converts the instance to an array. * * @return array */ public function toArray(): array { $result = parent::toArray(); $result['ref'] = (is_object($this->ref) && method_exists($this->ref, 'toArray')) ? $this->ref->toArray() : $this->ref; $result['argument'] = $this->argument->toArray(); if ($this->context !== null) { $result['context'] = $this->context->toArray(); } return $result; } /** * @return \WP\McpSchema\Server\Core\DTO\PromptReference|\WP\McpSchema\Server\Core\DTO\ResourceTemplateReference */ public function getRef() { return $this->ref; } /** * @return \WP\McpSchema\Server\Core\DTO\CompleteRequestParamsArgument */ public function getArgument(): CompleteRequestParamsArgument { return $this->argument; } /** * @return \WP\McpSchema\Server\Core\DTO\CompleteRequestParamsContext|null */ public function getContext(): ?CompleteRequestParamsContext { return $this->context; } }