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

MessageInfo{}WC 1.0└─ Message

MessageInfo class.

Represents an info message object as defined in the Agentic Commerce Protocol.

No Hooks.

Usage

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

Methods

  1. public __construct( $content, $param = null )
  2. public is_error()
  3. public to_array()

MessageInfo{} code WC 10.7.0

class MessageInfo extends Message {
	/**
	 * The error type (always 'error' for message errors).
	 *
	 * @var string
	 */
	private $type = MessageType::INFO;

	/**
	 * Constructor.
	 *
	 * @param string      $content Error content/message.
	 * @param string|null $param   RFC 9535 JSONPath (optional).
	 */
	public function __construct( $content, $param = null ) {
		$this->content = $content;
		$this->param   = $param;
	}

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

	/**
	 * Convert the error to an array.
	 *
	 * @return array A message for the `messages` array of the response.
	 */
	public function to_array(): array {
		$data = array(
			'type'         => $this->type,
			'content_type' => $this->content_type,
			'content'      => $this->content,
		);

		if ( null !== $this->param ) {
			$data['param'] = $this->param;
		}

		return $data;
	}
}