> */ public const REGISTRY = [ 'text' => TextContent::class, 'image' => ImageContent::class, 'audio' => AudioContent::class, 'tool_use' => ToolUseContent::class, 'tool_result' => ToolResultContent::class, ]; /** * Creates an instance from an array. * * @param array $data * @return SamplingMessageContentBlockInterface * @throws \InvalidArgumentException */ public static function fromArray(array $data): SamplingMessageContentBlockInterface { if (!isset($data['type'])) { throw new \InvalidArgumentException('Missing discriminator field: type'); } /** @var string $type */ $type = $data['type']; if (!isset(self::REGISTRY[$type])) { throw new \InvalidArgumentException(sprintf( "Unknown type value '%s'. Valid values: %s", $type, implode(', ', array_keys(self::REGISTRY)) )); } $class = self::REGISTRY[$type]; return $class::fromArray($data); } /** * Checks if a type value is supported by this factory. * * @param string $type * @return bool */ public static function supports(string $type): bool { return isset(self::REGISTRY[$type]); } /** * Returns all supported type values. * * @return array */ public static function types(): array { return array_keys(self::REGISTRY); } }