class Response implements Arrayable, Stringable

Properties

protected int|null $status

The HTTP response status code.

Methods

__construct(bool $allowed, string|null $message = '', int|string|null $code = null)

Create a new response.

static Response
allow(string|null $message = null, int|string|null $code = null)

Create a new "allow" Response.

static Response
deny(string|null $message = null, int|string|null $code = null)

Create a new "deny" Response.

static Response
denyWithStatus(int $status, string|null $message = null, int|string|null $code = null)

Create a new "deny" Response with a HTTP status code.

static Response
denyAsNotFound(string|null $message = null, int|string|null $code = null)

Create a new "deny" Response with a 404 HTTP status code.

bool
allowed()

Determine if the response was allowed.

bool
denied()

Determine if the response was denied.

string|null
message()

Get the response message.

int|string|null
code()

Get the response code / reason.

authorize()

Throw authorization exception if response was denied.

withStatus(int|null $status)

Set the HTTP response status code.

asNotFound()

Set the HTTP response status code to 404.

int|null
status()

Get the HTTP status code.

array
toArray()

Convert the response to an array.

string
__toString()

Get the string representation of the message.

Details

at line 24
__construct(bool $allowed, string|null $message = '', int|string|null $code = null)

Create a new response.

Parameters

bool $allowed

indicates whether the response was allowed

string|null $message

the response message

int|string|null $code

the response code

at line 34
static Response allow(string|null $message = null, int|string|null $code = null)

Create a new "allow" Response.

Parameters

string|null $message
int|string|null $code

Return Value

Response

at line 42
static Response deny(string|null $message = null, int|string|null $code = null)

Create a new "deny" Response.

Parameters

string|null $message
int|string|null $code

Return Value

Response

at line 50
static Response denyWithStatus(int $status, string|null $message = null, int|string|null $code = null)

Create a new "deny" Response with a HTTP status code.

Parameters

int $status
string|null $message
int|string|null $code

Return Value

Response

at line 58
static Response denyAsNotFound(string|null $message = null, int|string|null $code = null)

Create a new "deny" Response with a 404 HTTP status code.

Parameters

string|null $message
int|string|null $code

Return Value

Response

at line 66
bool allowed()

Determine if the response was allowed.

Return Value

bool

at line 74
bool denied()

Determine if the response was denied.

Return Value

bool

at line 82
string|null message()

Get the response message.

Return Value

string|null

at line 90
int|string|null code()

Get the response code / reason.

Return Value

int|string|null

at line 100
Response authorize()

Throw authorization exception if response was denied.

Return Value

Response

Exceptions

AuthorizationException

at line 114
Response withStatus(int|null $status)

Set the HTTP response status code.

Parameters

int|null $status

Return Value

Response

at line 124
Response asNotFound()

Set the HTTP response status code to 404.

Return Value

Response

at line 132
int|null status()

Get the HTTP status code.

Return Value

int|null

at line 140
array toArray()

Convert the response to an array.

Return Value

array

at line 152
string __toString()

Get the string representation of the message.

Return Value

string