|null */ protected ?array $_meta; /** * @param \WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents $resource @since 2024-11-05 * @param \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations @since 2024-11-05 * @param array|null $_meta @since 2025-06-18 */ public function __construct( $resource, ?Annotations $annotations = null, ?array $_meta = null ) { $this->type = self::TYPE; $this->resource = $resource; $this->annotations = $annotations; $this->_meta = $_meta; } /** * Creates an instance from an array. * * @param array{ * type: 'resource', * resource: \WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents, * annotations?: array|\WP\McpSchema\Common\Protocol\DTO\Annotations|null, * _meta?: array|null * } $data * @phpstan-param array $data * @return self */ public static function fromArray(array $data): self { self::assertRequired($data, ['resource']); /** @var \WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents $resource */ $resource = $data['resource']; /** @var \WP\McpSchema\Common\Protocol\DTO\Annotations|null $annotations */ $annotations = isset($data['annotations']) ? (is_array($data['annotations']) ? Annotations::fromArray(self::asArray($data['annotations'])) : $data['annotations']) : null; return new self( $resource, $annotations, self::asArrayOrNull($data['_meta'] ?? null) ); } /** * Converts the instance to an array. * * @return array */ public function toArray(): array { $result = []; $result['type'] = $this->type; $result['resource'] = (is_object($this->resource) && method_exists($this->resource, 'toArray')) ? $this->resource->toArray() : $this->resource; if ($this->annotations !== null) { $result['annotations'] = $this->annotations->toArray(); } if ($this->_meta !== null) { $result['_meta'] = $this->_meta; } return $result; } /** * @return 'resource' */ public function getType(): string { return $this->type; } /** * @return \WP\McpSchema\Common\Protocol\DTO\TextResourceContents|\WP\McpSchema\Common\Protocol\DTO\BlobResourceContents */ public function getResource() { return $this->resource; } /** * @return \WP\McpSchema\Common\Protocol\DTO\Annotations|null */ public function getAnnotations(): ?Annotations { return $this->annotations; } /** * @return array|null */ public function get_meta(): ?array { return $this->_meta; } }