ResponseFactory
class ResponseFactory
Traits
Properties
| protected null|array<string, mixed> | $meta | from HasMeta | |
| protected null|array<string, mixed> | $structuredContent | from HasStructuredContent | |
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected Response> | $responses |
Methods
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Set response metadata using an array or key-value pair.
Set structured response content.
Merge structured content into the given response array.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Add result metadata.
Add structured result content.
Get the responses.
Get the result metadata.
Get the structured result content.
Details
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
in
HasMeta at line 21
void
setMeta(array|string $meta, mixed $value = null)
Set response metadata using an array or key-value pair.
in
HasMeta at line 46
array
mergeMeta(array $baseArray)
Merge metadata into the given response array.
in
HasStructuredContent at line 19
void
setStructuredContent(array $structuredContent)
Set structured response content.
in
HasStructuredContent at line 32
array
mergeStructuredContent(array $baseArray)
Merge structured content into the given response array.
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.
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.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
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.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 32
__construct(Response|array $responses)
Create a factory for one or more responses.
at line 52
ResponseFactory
withMeta(string|array $meta, mixed $value = null)
Add result metadata.
at line 64
ResponseFactory
withStructuredContent(array $structuredContent)
Add structured result content.
at line 76
Collection
responses()
Get the responses.
at line 86
array|null
getMeta()
Get the result metadata.
at line 96
array|null
getStructuredContent()
Get the structured result content.