class ResponseSequence

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected bool $failWhenEmpty

Indicates that invoking this sequence when it is empty should throw an exception.

protected PromiseInterface $emptyResponse

The response that should be returned when the sequence is empty.

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(array $responses)

Create a new response sequence.

push(array|string|null $body = null, int $status = 200, array $headers = [])

Push a response to the sequence.

pushStatus(int $status, array $headers = [])

Push a response with the given status code to the sequence.

pushFile(string $filePath, int $status = 200, array $headers = [])

Push a response with the contents of a file as the body to the sequence.

pushFailedConnection(string|null $message = null)

Push a connection exception to the sequence.

pushResponse(mixed $response)

Push a response to the sequence.

whenEmpty(Closure|PromiseInterface $response)

Make the sequence return a default response when it is empty.

dontFailWhenEmpty()

Make the sequence return a default response when it is empty.

bool
isEmpty()

Indicate that this sequence has depleted all of its responses.

mixed
__invoke(Request $request)

Get the next response in the sequence.

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 29
__construct(array $responses)

Create a new response sequence.

Parameters

array $responses

at line 37
ResponseSequence push(array|string|null $body = null, int $status = 200, array $headers = [])

Push a response to the sequence.

Parameters

array|string|null $body
int $status
array $headers

Return Value

ResponseSequence

at line 47
ResponseSequence pushStatus(int $status, array $headers = [])

Push a response with the given status code to the sequence.

Parameters

int $status
array $headers

Return Value

ResponseSequence

at line 57
ResponseSequence pushFile(string $filePath, int $status = 200, array $headers = [])

Push a response with the contents of a file as the body to the sequence.

Parameters

string $filePath
int $status
array $headers

Return Value

ResponseSequence

at line 69
ResponseSequence pushFailedConnection(string|null $message = null)

Push a connection exception to the sequence.

Parameters

string|null $message

Return Value

ResponseSequence

at line 79
ResponseSequence pushResponse(mixed $response)

Push a response to the sequence.

Parameters

mixed $response

Return Value

ResponseSequence

at line 89
ResponseSequence whenEmpty(Closure|PromiseInterface $response)

Make the sequence return a default response when it is empty.

Parameters

Closure|PromiseInterface $response

Return Value

ResponseSequence

at line 100
ResponseSequence dontFailWhenEmpty()

Make the sequence return a default response when it is empty.

Return Value

ResponseSequence

at line 108
bool isEmpty()

Indicate that this sequence has depleted all of its responses.

Return Value

bool

at line 118
mixed __invoke(Request $request)

Get the next response in the sequence.

Parameters

Request $request

Return Value

mixed

Exceptions

OutOfBoundsException

at line 136
static void flushState()

Flush all static state.

Return Value

void