Skip to content

TextResponse

github-actions edited this page Mar 29, 2026 · 1 revision

Class TextResponse.

Represents an HTTP response containing plain text content.

This class MUST be used to generate HTTP responses with a text/plain content type. It automatically sets the 'Content-Type' header, encodes the body using the specified charset, and applies the HTTP 200 (OK) status code by default.


  • Full name: \FastForward\Http\Message\TextResponse
  • Parent class: Response
  • This class is marked as final and can't be subclassed
  • This class is a Final class

Methods

__construct

Constructs a new TextResponse instance.

public __construct(string $text, string $charset = 'utf-8', array $headers = []): mixed

This constructor SHALL set the 'Content-Type' header to text/plain with the specified charset and initialize the response body with the provided plain text content. The response status code will be set to 200 (OK) by default, with the corresponding reason phrase.

Parameters:

Parameter Type Description
$text string the plain text content to send in the response body
$charset string The character encoding to declare in the 'Content-Type' header. Defaults to 'utf-8'.
$headers array optional additional headers to include in the response

Clone this wiki locally