class Response extends Response implements Transient

Traits

Inline Symfony's side-effect-free common response preparation path.

Properties

static protected array $macros

The registered string macros.

from  Macroable
mixed $original

The original content of the response.

from  ResponseTrait
Throwable|null $exception

The exception that triggered the error response (if applicable).

from  ResponseTrait
static protected ResponseHeaderBag|null $headerPrototype

The pristine header bag cloned for each response.

static protected int $headerPrototypeTimestamp

Unix second represented by the prototype's Date header.

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

prepare(Request $request)

Prepare the response before it is emitted.

int
status()

Get the status code for the response.

string
statusText()

Get the status text for the response.

string
content()

Get the content of the response.

mixed
getOriginalContent()

Get the original response content.

header(string $key, array|string $values, bool $replace = true)

Set a header on the Response.

withHeaders(HeaderBag|array $headers)

Add an array of headers to the response.

withoutHeader(array|string $key)

Remove a header(s) from the response.

cookie(mixed $cookie)

Add a cookie to the response.

withCookie(mixed $cookie)

Add a cookie to the response.

withCookies(array $cookies)

Add multiple cookies to the response.

withoutCookie(mixed $cookie, string|null $path = null, string|null $domain = null)

Expire a cookie when sending the response.

withoutCookies(array $cookies, string|null $path = null, string|null $domain = null)

Expire multiple cookies when sending the response.

string|null
getCallback()

Get the callback of the response.

withException(Throwable $e)

Set the exception to attach to the response.

never
throwResponse()

Throw the response in a HttpResponseException instance.

__construct(mixed $content = '', int $status = 200, array|ResponseHeaderBag $headers = [])

Create a new HTTP response.

string
getContent()

Get the response content.

setContent(mixed $content)

Set the content on the response.

bool
shouldBeJson(mixed $content)

Determine if the given content should be turned into JSON.

string|false
morphToJson(mixed $content)

Morph the given content into JSON.

never
sendHeaders(int|null $statusCode = null)

Send HTTP headers.

never
sendContent()

Send response content.

never
send(bool $flush = true)

Send HTTP headers and content.

static void
flushState()

Flush all static state.

Details

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in PreparesResponse at line 21
PreparesResponse prepare(Request $request)

Prepare the response before it is emitted.

Parameters

Request $request

Return Value

PreparesResponse

in ResponseTrait at line 26
int status()

Get the status code for the response.

Return Value

int

in ResponseTrait at line 34
string statusText()

Get the status text for the response.

Return Value

string

in ResponseTrait at line 42
string content()

Get the content of the response.

Return Value

string

in ResponseTrait at line 50
mixed getOriginalContent()

Get the original response content.

Return Value

mixed

in ResponseTrait at line 62
ResponseTrait header(string $key, array|string $values, bool $replace = true)

Set a header on the Response.

Parameters

string $key
array|string $values
bool $replace

Return Value

ResponseTrait

in ResponseTrait at line 74
ResponseTrait withHeaders(HeaderBag|array $headers)

Add an array of headers to the response.

Parameters

HeaderBag|array $headers

Return Value

ResponseTrait

in ResponseTrait at line 92
ResponseTrait withoutHeader(array|string $key)

Remove a header(s) from the response.

Parameters

array|string $key

Return Value

ResponseTrait

Add a cookie to the response.

Parameters

mixed $cookie

Return Value

ResponseTrait

in ResponseTrait at line 116
ResponseTrait withCookie(mixed $cookie)

Add a cookie to the response.

Parameters

mixed $cookie

Return Value

ResponseTrait

in ResponseTrait at line 132
ResponseTrait withCookies(array $cookies)

Add multiple cookies to the response.

Parameters

array $cookies

Return Value

ResponseTrait

in ResponseTrait at line 146
ResponseTrait withoutCookie(mixed $cookie, string|null $path = null, string|null $domain = null)

Expire a cookie when sending the response.

Parameters

mixed $cookie
string|null $path
string|null $domain

Return Value

ResponseTrait

in ResponseTrait at line 162
ResponseTrait withoutCookies(array $cookies, string|null $path = null, string|null $domain = null)

Expire multiple cookies when sending the response.

Parameters

array $cookies
string|null $path
string|null $domain

Return Value

ResponseTrait

in ResponseTrait at line 174
string|null getCallback()

Get the callback of the response.

Return Value

string|null

in ResponseTrait at line 184
ResponseTrait withException(Throwable $e)

Set the exception to attach to the response.

Parameters

Throwable $e

Return Value

ResponseTrait

in ResponseTrait at line 196
never throwResponse()

Throw the response in a HttpResponseException instance.

Return Value

never

Exceptions

HttpResponseException

at line 44
__construct(mixed $content = '', int $status = 200, array|ResponseHeaderBag $headers = [])

Create a new HTTP response.

Parameters

mixed $content
int $status
array|ResponseHeaderBag $headers

Exceptions

InvalidArgumentException

at line 77
string getContent()

Get the response content.

Return Value

string

at line 90
Response setContent(mixed $content)

Set the content on the response.

Parameters

mixed $content

Return Value

Response

Exceptions

InvalidArgumentException

at line 129
protected bool shouldBeJson(mixed $content)

Determine if the given content should be turned into JSON.

Parameters

mixed $content

Return Value

bool

at line 141
protected string|false morphToJson(mixed $content)

Morph the given content into JSON.

Parameters

mixed $content

Return Value

string|false

at line 158
never sendHeaders(int|null $statusCode = null)

Send HTTP headers.

Parameters

int|null $statusCode

Return Value

never

Exceptions

RuntimeException

at line 169
never sendContent()

Send response content.

Return Value

never

Exceptions

RuntimeException

at line 180
never send(bool $flush = true)

Send HTTP headers and content.

Parameters

bool $flush

Return Value

never

Exceptions

RuntimeException

at line 189
static void flushState()

Flush all static state.

Return Value

void