-
-
Notifications
You must be signed in to change notification settings - Fork 0
ResponseFactoryInterface
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
Creates an HTTP response containing HTML content.
public createResponseFromHtml(string $html): \Psr\Http\Message\ResponseInterfaceThe 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
Creates an HTTP response containing a JSON-encoded payload.
public createResponseFromPayload(array $payload): \FastForward\Http\Message\PayloadResponseInterfaceThe 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
Creates an HTTP response containing plain text content.
public createResponseFromText(string $text): \Psr\Http\Message\ResponseInterfaceThe 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
Creates an HTTP 204 No Content response.
public createResponseNoContent(array $headers): \Psr\Http\Message\ResponseInterfaceThe response MUST contain no body and MUST have status code 204.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$headers |
array |
Return Value:
the generated no content response
Creates an HTTP redirect response.
public createResponseRedirect(string|\Psr\Http\Message\UriInterface $uri, bool $permanent, array $headers): \Psr\Http\Message\ResponseInterfaceThe 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