ResponseSequence
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
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new response sequence.
Push a response to the sequence.
Push a response with the given status code to the sequence.
Push a response with the contents of a file as the body to the sequence.
Push a connection exception to the sequence.
Push a response to the sequence.
Make the sequence return a default response when it is empty.
Indicate that this sequence has depleted all of its responses.
Details
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 a response with the contents of a file as the body to the sequence.
$this
pushFailedConnection(string|null $message = null)
Push a connection exception 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(Request $request)
Get the next response in the sequence.