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

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.

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.

void
setMeta(array|string $meta, mixed $value = null)

Set response metadata using an array or key-value pair.

from  HasMeta
array
mergeMeta(array $baseArray)

Merge metadata into the given response array.

from  HasMeta
void
setStructuredContent(array $structuredContent)

Set structured response content.

array
mergeStructuredContent(array $baseArray)

Merge structured content into the given response array.

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

Create a factory for one or more responses.

withMeta(string|array $meta, mixed $value = null)

Add result metadata.

withStructuredContent(array $structuredContent)

Add structured result content.

responses()

Get the responses.

array|null
getMeta()

Get the result metadata.

array|null
getStructuredContent()

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.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

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.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in HasMeta at line 21
void setMeta(array|string $meta, mixed $value = null)

Set response metadata using an array or key-value pair.

Parameters

array|string $meta
mixed $value

Return Value

void

in HasMeta at line 46
array mergeMeta(array $baseArray)

Merge metadata into the given response array.

Parameters

array $baseArray

Return Value

array

void setStructuredContent(array $structuredContent)

Set structured response content.

Parameters

array $structuredContent

Return Value

void

array mergeStructuredContent(array $baseArray)

Merge structured content into the given response array.

Parameters

array $baseArray

Return Value

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.

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

Create a factory for one or more responses.

Parameters

Response|array $responses

at line 52
ResponseFactory withMeta(string|array $meta, mixed $value = null)

Add result metadata.

Parameters

string|array $meta
mixed $value

Return Value

ResponseFactory

at line 64
ResponseFactory withStructuredContent(array $structuredContent)

Add structured result content.

Parameters

array $structuredContent

Return Value

ResponseFactory

at line 76
Collection responses()

Get the responses.

Return Value

Collection

at line 86
array|null getMeta()

Get the result metadata.

Return Value

array|null

at line 96
array|null getStructuredContent()

Get the structured result content.

Return Value

array|null