class ResponseFactory implements ResponseFactory

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Factory $view

The view factory instance.

protected Redirector $redirector

The redirector instance.

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.

__construct(Factory $view, Redirector $redirector)

Create a new response factory instance.

make(mixed $content = '', int $status = 200, array $headers = [])

Create a new response instance.

noContent(int $status = 204, array $headers = [])

Create a new "no content" response.

view(array|string $view, array $data = [], int $status = 200, array $headers = [])

Create a new response for a given view.

json(mixed $data = [], int $status = 200, array $headers = [], int $options = 0)

Create a new JSON response instance.

jsonp(string $callback, mixed $data = [], int $status = 200, array $headers = [], int $options = 0)

Create a new JSONP response instance.

StreamedResponse
eventStream(Closure $callback, array $headers = [], StreamedEvent|string|null $endStreamWith = '</stream>')

Create a new event stream response.

StreamedResponse
stream(callable $callback = null, int $status = 200, array $headers = [])

Create a new streamed response instance.

StreamedJsonResponse
streamJson(array $data, int $status = 200, array $headers = [], int $encodingOptions = JsonResponse::DEFAULT_ENCODING_OPTIONS)

Create a new streamed JSON response instance.

StreamedResponse
streamDownload(callable $callback, string|null $name = null, array $headers = [], string $disposition = 'attachment')

Create a new streamed response instance as a file download.

BinaryFileResponse
download(SplFileInfo|string $file, string|null $name = null, array $headers = [], string $disposition = 'attachment')

Create a new file download response.

string
fallbackName(string $name)

Convert the string to ASCII characters that are equivalent to the given name.

BinaryFileResponse
file(SplFileInfo|string $file, array $headers = [])

Return the raw contents of a binary file.

redirectTo(string $path, int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response to the given path.

redirectToRoute(BackedEnum|string $route, mixed $parameters = [], int $status = 302, array $headers = [])

Create a new redirect response to a named route.

redirectToAction(array|string $action, mixed $parameters = [], int $status = 302, array $headers = [])

Create a new redirect response to a controller action.

redirectGuest(string $path, int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response, while putting the current URL in the session.

redirectToIntended(string $default = '/', int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response to the previously intended location.

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

at line 44
__construct(Factory $view, Redirector $redirector)

Create a new response factory instance.

Parameters

Factory $view
Redirector $redirector

at line 53
Response make(mixed $content = '', int $status = 200, array $headers = [])

Create a new response instance.

Parameters

mixed $content
int $status
array $headers

Return Value

Response

at line 61
Response noContent(int $status = 204, array $headers = [])

Create a new "no content" response.

Parameters

int $status
array $headers

Return Value

Response

at line 69
Response view(array|string $view, array $data = [], int $status = 200, array $headers = [])

Create a new response for a given view.

Parameters

array|string $view
array $data
int $status
array $headers

Return Value

Response

at line 81
JsonResponse json(mixed $data = [], int $status = 200, array $headers = [], int $options = 0)

Create a new JSON response instance.

Parameters

mixed $data
int $status
array $headers
int $options

Return Value

JsonResponse

at line 89
JsonResponse jsonp(string $callback, mixed $data = [], int $status = 200, array $headers = [], int $options = 0)

Create a new JSONP response instance.

Parameters

string $callback
mixed $data
int $status
array $headers
int $options

Return Value

JsonResponse

at line 97
StreamedResponse eventStream(Closure $callback, array $headers = [], StreamedEvent|string|null $endStreamWith = '</stream>')

Create a new event stream response.

Parameters

Closure $callback
array $headers
StreamedEvent|string|null $endStreamWith

Return Value

StreamedResponse

at line 151
StreamedResponse stream(callable $callback = null, int $status = 200, array $headers = [])

Create a new streamed response instance.

Generator callbacks are invoked once and retained as iterable chunks so the Swoole bridge can stop production immediately after a failed socket write.

Parameters

callable $callback
int $status
array $headers

Return Value

StreamedResponse

at line 171
StreamedJsonResponse streamJson(array $data, int $status = 200, array $headers = [], int $encodingOptions = JsonResponse::DEFAULT_ENCODING_OPTIONS)

Create a new streamed JSON response instance.

Parameters

array $data
int $status
array $headers
int $encodingOptions

Return Value

StreamedJsonResponse

at line 181
StreamedResponse streamDownload(callable $callback, string|null $name = null, array $headers = [], string $disposition = 'attachment')

Create a new streamed response instance as a file download.

Parameters

callable $callback
string|null $name
array $headers
string $disposition

Return Value

StreamedResponse

Exceptions

StreamedResponseException

at line 207
BinaryFileResponse download(SplFileInfo|string $file, string|null $name = null, array $headers = [], string $disposition = 'attachment')

Create a new file download response.

Parameters

SplFileInfo|string $file
string|null $name
array $headers
string $disposition

Return Value

BinaryFileResponse

at line 221
protected string fallbackName(string $name)

Convert the string to ASCII characters that are equivalent to the given name.

Parameters

string $name

Return Value

string

at line 229
BinaryFileResponse file(SplFileInfo|string $file, array $headers = [])

Return the raw contents of a binary file.

Parameters

SplFileInfo|string $file
array $headers

Return Value

BinaryFileResponse

at line 237
RedirectResponse redirectTo(string $path, int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response to the given path.

Parameters

string $path
int $status
array $headers
bool|null $secure

Return Value

RedirectResponse

at line 245
RedirectResponse redirectToRoute(BackedEnum|string $route, mixed $parameters = [], int $status = 302, array $headers = [])

Create a new redirect response to a named route.

Parameters

BackedEnum|string $route
mixed $parameters
int $status
array $headers

Return Value

RedirectResponse

at line 253
RedirectResponse redirectToAction(array|string $action, mixed $parameters = [], int $status = 302, array $headers = [])

Create a new redirect response to a controller action.

Parameters

array|string $action
mixed $parameters
int $status
array $headers

Return Value

RedirectResponse

at line 261
RedirectResponse redirectGuest(string $path, int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response, while putting the current URL in the session.

Parameters

string $path
int $status
array $headers
bool|null $secure

Return Value

RedirectResponse

at line 269
RedirectResponse redirectToIntended(string $default = '/', int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response to the previously intended location.

Parameters

string $default
int $status
array $headers
bool|null $secure

Return Value

RedirectResponse

at line 277
static void flushState()

Flush all static state.

Return Value

void