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 Closure|PromiseInterface|null $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(mixed $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 30
static void macro(string $name, callable|object $macro)

Register a custom macro.

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 44
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

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 61
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 72
static void flushMacros()

Flush the existing macros.

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

Return Value

void

in Macroable at line 83
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 108
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 30
__construct(array $responses)

Create a new response sequence.

Parameters

array $responses

at line 41
ResponseSequence push(mixed $body = null, int $status = 200, array $headers = [])

Push a response to the sequence.

Parameters

mixed $body
int $status
array $headers

Return Value

ResponseSequence

at line 53
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 65
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 79
ResponseSequence pushFailedConnection(string|null $message = null)

Push a connection exception to the sequence.

Parameters

string|null $message

Return Value

ResponseSequence

at line 91
ResponseSequence pushResponse(mixed $response)

Push a response to the sequence.

Parameters

mixed $response

Return Value

ResponseSequence

at line 103
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 116
ResponseSequence dontFailWhenEmpty()

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

Return Value

ResponseSequence

at line 124
bool isEmpty()

Indicate that this sequence has depleted all of its responses.

Return Value

bool

at line 134
mixed __invoke(Request $request)

Get the next response in the sequence.

Parameters

Request $request

Return Value

mixed

Exceptions

OutOfBoundsException

at line 152
static void flushState()

Flush all static state.

Return Value

void