Skip to content

ResponseFactoryInterface

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

Interface ResponseFactoryInterface.

Extends PSR-17 ResponseFactoryInterface and defines additional convenience methods for generating common types of HTTP responses, including HTML, plain text, JSON payloads, redirects, and empty responses.

Implementations of this interface MUST comply with the method requirements and MUST return immutable instances as per PSR-7 standards.


  • Full name: \FastForward\Http\Message\Factory\ResponseFactoryInterface
  • Parent interfaces: ResponseFactoryInterface

Methods

createResponseFromHtml

Creates an HTTP response containing HTML content.

public createResponseFromHtml(string $html): \Psr\Http\Message\ResponseInterface

The response MUST have 'Content-Type: text/html' set automatically.

Parameters:

Parameter Type Description
$html string the HTML content to include in the response body

Return Value:

the generated HTML response


createResponseFromPayload

Creates an HTTP response containing a JSON-encoded payload.

public createResponseFromPayload(array $payload): \FastForward\Http\Message\PayloadResponseInterface

The response MUST have 'Content-Type: application/json' set automatically.

Parameters:

Parameter Type Description
$payload array the payload to encode as JSON

Return Value:

the generated JSON response


createResponseFromText

Creates an HTTP response containing plain text content.

public createResponseFromText(string $text): \Psr\Http\Message\ResponseInterface

The response MUST have 'Content-Type: text/plain' set automatically.

Parameters:

Parameter Type Description
$text string the plain text content to include in the response body

Return Value:

the generated plain text response


createResponseNoContent

Creates an HTTP 204 No Content response.

public createResponseNoContent(array $headers): \Psr\Http\Message\ResponseInterface

The response MUST contain no body and MUST have status code 204.

Parameters:

Parameter Type Description
$headers array

Return Value:

the generated no content response


createResponseRedirect

Creates an HTTP redirect response.

public createResponseRedirect(string|\Psr\Http\Message\UriInterface $uri, bool $permanent, array $headers): \Psr\Http\Message\ResponseInterface

The response MUST include a 'Location' header and an appropriate status code: 301 (permanent) if $permanent is true, or 302 (temporary) otherwise.

Parameters:

Parameter Type Description
$uri string|\Psr\Http\Message\UriInterface the target location for the redirect
$permanent bool if true, issues a permanent redirect; otherwise, temporary
$headers array

Return Value:

the generated redirect response


Clone this wiki locally