class ResponseSequence (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected array $responses

The responses in the sequence.

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, object|callable $macro)

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

Checks 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.

void
__construct(array $responses)

Create a new response sequence.

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

Push a response to the sequence.

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

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

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

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

$this
pushResponse(mixed $response)

Push a response to the sequence.

$this
whenEmpty(PromiseInterface|Closure $response)

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

$this
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()

Get the next response in the sequence.

Details

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(array $responses)

Create a new response sequence.

Parameters

array $responses

Return Value

void

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

Push a response to the sequence.

Parameters

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

Return Value

$this

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

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

Parameters

int $status
array $headers

Return Value

$this

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

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

Parameters

string $filePath
int $status
array $headers

Return Value

$this

$this pushResponse(mixed $response)

Push a response to the sequence.

Parameters

mixed $response

Return Value

$this

$this whenEmpty(PromiseInterface|Closure $response)

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

Parameters

PromiseInterface|Closure $response

Return Value

$this

$this dontFailWhenEmpty()

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

Return Value

$this

bool isEmpty()

Indicate that this sequence has depleted all of its responses.

Return Value

bool

mixed __invoke()

Get the next response in the sequence.

Return Value

mixed

Exceptions

OutOfBoundsException