|null $annotations Optional annotations. * @param mixed $_meta Optional block metadata, carried as given. * @return array */ public static function image( string $data, $mime_type, ?array $annotations = null, $_meta = null ): array { return self::without_nulls( array( 'type' => 'image', 'data' => $data, 'mimeType' => $mime_type, 'annotations' => $annotations, '_meta' => $_meta, ) ); } /** * Build embedded text resource content. * * @since 0.6.0 Added the optional $resource_meta parameter. * * @param string $uri Resource URI. * @param string $text Resource text. * @param mixed $mime_type MIME type, carried as given. * @param array|null $annotations Optional block annotations. * @param mixed $_meta Optional block metadata, carried as given. * @param mixed $resource_meta Optional resource metadata, carried as given. * @return array */ public static function embedded_text_resource( string $uri, string $text, $mime_type = null, ?array $annotations = null, $_meta = null, $resource_meta = null ): array { return self::embedded_resource( self::without_nulls( array( 'uri' => $uri, 'text' => $text, 'mimeType' => $mime_type, '_meta' => $resource_meta, ) ), $annotations, $_meta ); } /** * Build embedded blob resource content. * * @since 0.6.0 Added the optional $resource_meta parameter. * * @param string $uri Resource URI. * @param string $blob Base64 resource data. * @param mixed $mime_type MIME type, carried as given. * @param array|null $annotations Optional block annotations. * @param mixed $_meta Optional block metadata, carried as given. * @param mixed $resource_meta Optional resource metadata, carried as given. * @return array */ public static function embedded_blob_resource( string $uri, string $blob, $mime_type = null, ?array $annotations = null, $_meta = null, $resource_meta = null ): array { return self::embedded_resource( self::without_nulls( array( 'uri' => $uri, 'blob' => $blob, 'mimeType' => $mime_type, '_meta' => $resource_meta, ) ), $annotations, $_meta ); } /** * Build text content. * * @param string $text Text. * @param array|null $annotations Optional annotations. * @param mixed $_meta Optional block metadata, carried as given. * @return array */ public static function text( string $text, ?array $annotations = null, $_meta = null ): array { return self::without_nulls( array( 'type' => 'text', 'text' => $text, 'annotations' => $annotations, '_meta' => $_meta, ) ); } /** * Build the embedded wrapper. * * @param array $resource_data Resource contents. * @param array|null $annotations Optional block annotations. * @param mixed $_meta Optional block metadata, carried as given. * @return array */ private static function embedded_resource( array $resource_data, ?array $annotations, $_meta ): array { return self::without_nulls( array( 'type' => 'resource', 'resource' => $resource_data, 'annotations' => $annotations, '_meta' => $_meta, ) ); } /** * Remove optional null fields without reindexing the remaining values. * * @param array $data Content or resource fields. * * @return array Fields retaining false, zero, and empty-string values. */ private static function without_nulls( array $data ): array { return array_filter( $data, static fn( $value ): bool => null !== $value ); } }