class Response implements Arrayable (View source)

Properties

protected bool $allowed

Indicates whether the response was allowed.

protected string|null $message

The response message.

protected mixed $code

The response code.

protected int|null $status

The HTTP response status code.

Methods

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

Create a new response.

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

Create a new "allow" Response.

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

Create a new "deny" Response.

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

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

static Response
denyAsNotFound(string|null $message = null, mixed $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.

mixed
code()

Get the response code / reason.

authorize()

Throw authorization exception if response was denied.

$this
withStatus(null|int $status)

Set the HTTP response status code.

$this
asNotFound()

Set the HTTP response status code to 404.

int|null
status()

Get the HTTP status code.

toArray()

Convert the response to an array.

string
__toString()

Get the string representation of the message.

Details

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

Create a new response.

Parameters

bool $allowed
string|null $message
mixed $code

Return Value

void

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

Create a new "allow" Response.

Parameters

string|null $message
mixed $code

Return Value

Response

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

Create a new "deny" Response.

Parameters

string|null $message
mixed $code

Return Value

Response

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

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

Parameters

int $status
string|null $message
mixed $code

Return Value

Response

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

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

Parameters

string|null $message
mixed $code

Return Value

Response

bool allowed()

Determine if the response was allowed.

Return Value

bool

bool denied()

Determine if the response was denied.

Return Value

bool

string|null message()

Get the response message.

Return Value

string|null

mixed code()

Get the response code / reason.

Return Value

mixed

Response authorize()

Throw authorization exception if response was denied.

Return Value

Response

Exceptions

AuthorizationException

$this withStatus(null|int $status)

Set the HTTP response status code.

Parameters

null|int $status

Return Value

$this

$this asNotFound()

Set the HTTP response status code to 404.

Return Value

$this

int|null status()

Get the HTTP status code.

Return Value

int|null

toArray()

Convert the response to an array.

string __toString()

Get the string representation of the message.

Return Value

string