Methods |
protected
|
respond(array|string|null $data = null, ?int $status = null, string $message = ''): ResponseInterface
Provides a single, simple method to return an API response, formatted
to match the requested format, with proper…
Provides a single, simple method to return an API response, formatted
to match the requested format, with proper content-type and status code.
|
#
|
protected
|
fail(array|string $messages, int $status = 400, string|null $code = null, string $customMessage = ''): ResponseInterface
Used for generic failures that no custom methods exist for.
Used for generic failures that no custom methods exist for.
Parameters
$status |
HTTP status code
|
$code |
Custom, API-specific, error code
|
|
#
|
protected
|
respondCreated(array|string|null $data = null, string $message = ''): ResponseInterface
Used after successfully creating a new resource.
Used after successfully creating a new resource.
|
#
|
protected
|
respondDeleted(array|string|null $data = null, string $message = ''): ResponseInterface
Used after a resource has been successfully deleted.
Used after a resource has been successfully deleted.
|
#
|
protected
|
respondUpdated(array|string|null $data = null, string $message = ''): ResponseInterface
Used after a resource has been successfully updated.
Used after a resource has been successfully updated.
|
#
|
protected
|
respondNoContent(string $message = 'No Content'): ResponseInterface
Used after a command has been successfully executed but there is no
meaningful reply to send back to the client.
Used after a command has been successfully executed but there is no
meaningful reply to send back to the client.
|
#
|
protected
|
failUnauthorized(string $description = 'Unauthorized', ?string $code = null, string $message = ''): ResponseInterface
Used when the client is either didn't send authorization information,
or had bad authorization credentials. User is…
Used when the client is either didn't send authorization information,
or had bad authorization credentials. User is encouraged to try again
with the proper information.
|
#
|
protected
|
failForbidden(string $description = 'Forbidden', ?string $code = null, string $message = ''): ResponseInterface
Used when access is always denied to this resource and no amount
of trying again will help.
Used when access is always denied to this resource and no amount
of trying again will help.
|
#
|
protected
|
failNotFound(string $description = 'Not Found', ?string $code = null, string $message = ''): ResponseInterface
Used when a specified resource cannot be found.
Used when a specified resource cannot be found.
|
#
|
protected
|
failValidationError(string $description = 'Bad Request', ?string $code = null, string $message = ''): ResponseInterface
Used when the data provided by the client cannot be validated.
Used when the data provided by the client cannot be validated.
Deprecated
Use failValidationErrors instead
|
#
|
protected
|
failValidationErrors(string|string[] $errors, ?string $code = null, string $message = ''): ResponseInterface
Used when the data provided by the client cannot be validated on one or more fields.
Used when the data provided by the client cannot be validated on one or more fields.
|
#
|
protected
|
failResourceExists(string $description = 'Conflict', ?string $code = null, string $message = ''): ResponseInterface
Use when trying to create a new resource and it already exists.
Use when trying to create a new resource and it already exists.
|
#
|
protected
|
failResourceGone(string $description = 'Gone', ?string $code = null, string $message = ''): ResponseInterface
Use when a resource was previously deleted. This is different than
Not Found, because here we know the data previously…
Use when a resource was previously deleted. This is different than
Not Found, because here we know the data previously existed, but is now gone,
where Not Found means we simply cannot find any information about it.
|
#
|
protected
|
failTooManyRequests(
string $description = 'Too Many Requests',
?string $code = null,
string $message = '',
): ResponseInterface
Used when the user has made too many requests for the resource recently.
Used when the user has made too many requests for the resource recently.
|
#
|
protected
|
failServerError(
string $description = 'Internal Server Error',
string|null $code = null,
string $message = '',
): ResponseInterface
Used when there is a server error.
Used when there is a server error.
Parameters
$description |
The error message to show the user.
|
$code |
A custom, API-specific, error code.
|
$message |
A custom "reason" message to return.
|
|
#
|
protected
|
format(array|string|null $data = null): string|null
Handles formatting a response. Currently makes some heavy assumptions
and needs updating! :)
Handles formatting a response. Currently makes some heavy assumptions
and needs updating! :)
|
#
|
protected
|
setResponseFormat(?string $format = null): $this
Sets the format the response should be in.
Sets the format the response should be in.
|
#
|
Properties |
protected
|
array<string, int>
|
$codes = [
'created' => 201,
'deleted' => 200,
'updated' => 200,
'no_content' => 204,
'invalid_request' => 400,
'unsupported_response_type' => 400,
'invalid_scope' => 400,
'temporarily_unavailable' => 400,
'invalid_grant' => 400,
'invalid_credentials' => 400,
'invalid_refresh' => 400,
'no_data' => 400,
'invalid_data' => 400,
'access_denied' => 401,
'unauthorized' => 401,
'invalid_client' => 401,
'forbidden' => 403,
'resource_not_found' => 404,
'not_acceptable' => 406,
'resource_exists' => 409,
'conflict' => 409,
'resource_gone' => 410,
'payload_too_large' => 413,
'unsupported_media_type' => 415,
'too_many_requests' => 429,
'server_error' => 500,
'unsupported_grant_type' => 501,
'not_implemented' => 501,
]
|
#
|
protected
|
string
|
$format = 'json'
|
#
|
protected
|
FormatterInterface|null
|
$formatter
|
#
|
public
|
IncomingRequest
|
$request
|
#
|
public
|
ResponseInterface
|
$response
|
#
|