Automattic\WooCommerce\StoreApi\Routes\V1\Agentic\Messages

Message{}abstractWC 1.0

Base class for error and info messages.

No Hooks.

Usage

$Message = new Message();
// use class methods

Methods

  1. public is_error()
  2. public to_array()
  3. public use_markdown()

Message{} code WC 10.7.0

abstract class Message {
	/**
	 * Content type for the error message.
	 *
	 * Defaults to plain, but could also be markdown.
	 *
	 * @var string
	 */
	protected $content_type = MessageContentType::PLAIN;

	/**
	 * Error content/message.
	 *
	 * @var string
	 */
	protected $content;

	/**
	 * RFC 9535 JSONPath to the problematic parameter (optional).
	 *
	 * @var string|null
	 */
	protected $param;

	/**
	 * Check if the message is an error.
	 *
	 * @return bool True if the message is an error, false otherwise.
	 */
	abstract public function is_error(): bool;

	/**
	 * Convert the message to an array.
	 *
	 * @return array A message for the `messages` array of the response.
	 */
	abstract public function to_array(): array;

	/**
	 * Use markdown content type for the content of the error.
	 */
	public function use_markdown() {
		$this->content_type = MessageContentType::MARKDOWN;
	}
}