HttpResponse
in package
implements
IHttpResponse
HTTP response implementation.
Concrete implementation of IHttpResponse used by both production and test clients.
Table of Contents
Interfaces
- IHttpResponse
- Interface for HTTP response abstraction.
Properties
- $body : string
- $errorCode : int
- $errorMessage : string
- $headers : array<string|int, mixed>
- $statusCode : int
Methods
- __construct() : mixed
- Create HTTP response
- getBody() : string
- Get response body
- getError() : string
- Get error message
- getErrorCode() : int
- Get error code
- getHeader() : string|null
- Get specific header value
- getHeaders() : array<string|int, mixed>
- Get response headers
- getStatusCode() : int
- Get HTTP status code
- hasError() : bool
- Check if request had an error (connection error, timeout, etc.)
- isSuccess() : bool
- Check if response is successful (2xx status code)
Properties
$body
private
string
$body
$errorCode
private
int
$errorCode
$errorMessage
private
string
$errorMessage
$headers
private
array<string|int, mixed>
$headers
$statusCode
private
int
$statusCode
Methods
__construct()
Create HTTP response
public
__construct([int $statusCode = 0 ][, string $body = '' ][, array<string|int, mixed> $headers = [] ][, int $errorCode = 0 ][, string $errorMessage = '' ]) : mixed
Parameters
- $statusCode : int = 0
-
HTTP status code
- $body : string = ''
-
Response body
- $headers : array<string|int, mixed> = []
-
Response headers
- $errorCode : int = 0
-
Error code (0 = no error)
- $errorMessage : string = ''
-
Error message
getBody()
Get response body
public
getBody() : string
Tags
Return values
string —Response body content
getError()
Get error message
public
getError() : string
Tags
Return values
string —Error message or empty string if no error
getErrorCode()
Get error code
public
getErrorCode() : int
Tags
Return values
int —Error code or 0 if no error
getHeader()
Get specific header value
public
getHeader(string $name) : string|null
Parameters
- $name : string
-
Header name
Tags
Return values
string|null —Header value or null if not found
getHeaders()
Get response headers
public
getHeaders() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of headers
getStatusCode()
Get HTTP status code
public
getStatusCode() : int
Tags
Return values
int —HTTP status code (200, 404, 500, etc.)
hasError()
Check if request had an error (connection error, timeout, etc.)
public
hasError() : bool
Tags
Return values
bool —True if error occurred
isSuccess()
Check if response is successful (2xx status code)
public
isSuccess() : bool
Tags
Return values
bool —True if status code is 2xx