class Response

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable

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.

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(Content $content, Role $role = Role::User, bool $isError = false)

Create a response with its content and role.

static Response
notification(string $method, array $params = [])

Create a notification response.

static Response
text(string $text)

Create a text response.

static Response
html(string $path)

Create a response from an HTML file.

static Response
view(string $view, array $data = [], array $mergeData = [])

Create a response from a rendered view.

static Response
json(mixed $content)

Create a response containing JSON text.

static Response
blob(string $content)

Create a binary response.

static ResponseFactory
structured(array $response)

Create a structured response with a text representation.

static Response
error(string $text)

Create an error response.

content()

Get the response content.

static ResponseFactory
make(Response|array $responses)

Create a response factory.

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

Add metadata to the response content.

static Response
audio(string $data, string $mimeType = 'audio/wav')

Create an audio response.

static Response
image(string $data, string $mimeType = 'image/png')

Create an image response.

static Response
resourceLink(string|Resource|ResourceLink $uri, string|null $name = null, string|null $mimeType = null, string|null $title = null, string|null $description = null, int|null $size = null, array $annotations = [], array $icons = [])

Create a resource link response.

static Response
fromStorage(string $path, string|null $disk = null, string|null $mimeType = null)

Create an image or audio response from a filesystem disk.

asAssistant()

Create a response with the assistant role.

bool
isNotification()

Determine whether the response is a notification.

bool
isError()

Determine whether the response represents an error.

Role
role()

Get the response role.

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 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 34
protected __construct(Content $content, Role $role = Role::User, bool $isError = false)

Create a response with its content and role.

Parameters

Content $content
Role $role
bool $isError

at line 46
static Response notification(string $method, array $params = [])

Create a notification response.

Parameters

string $method
array $params

Return Value

Response

at line 54
static Response text(string $text)

Create a text response.

Parameters

string $text

Return Value

Response

at line 62
static Response html(string $path)

Create a response from an HTML file.

Parameters

string $path

Return Value

Response

at line 79
static Response view(string $view, array $data = [], array $mergeData = [])

Create a response from a rendered view.

Parameters

string $view
array $data
array $mergeData

Return Value

Response

at line 91
static Response json(mixed $content)

internal  
 

Create a response containing JSON text.

Parameters

mixed $content

Return Value

Response

Exceptions

JsonException

at line 99
static Response blob(string $content)

Create a binary response.

Parameters

string $content

Return Value

Response

at line 109
static ResponseFactory structured(array $response)

Create a structured response with a text representation.

Parameters

array $response

Return Value

ResponseFactory

at line 129
static Response error(string $text)

Create an error response.

Parameters

string $text

Return Value

Response

at line 137
Content content()

Get the response content.

Return Value

Content

at line 147
static ResponseFactory make(Response|array $responses)

Create a response factory.

Parameters

Response|array $responses

Return Value

ResponseFactory

at line 157
Response withMeta(array|string $meta, mixed $value = null)

Add metadata to the response content.

Parameters

array|string $meta
mixed $value

Return Value

Response

at line 167
static Response audio(string $data, string $mimeType = 'audio/wav')

Create an audio response.

Parameters

string $data
string $mimeType

Return Value

Response

at line 175
static Response image(string $data, string $mimeType = 'image/png')

Create an image response.

Parameters

string $data
string $mimeType

Return Value

Response

Create a resource link response.

Parameters

string|Resource|ResourceLink $uri
string|null $name
string|null $mimeType
string|null $title
string|null $description
int|null $size
array $annotations
array $icons

Return Value

Response

at line 231
static Response fromStorage(string $path, string|null $disk = null, string|null $mimeType = null)

Create an image or audio response from a filesystem disk.

Parameters

string $path
string|null $disk
string|null $mimeType

Return Value

Response

at line 260
Response asAssistant()

Create a response with the assistant role.

Return Value

Response

at line 268
bool isNotification()

Determine whether the response is a notification.

Return Value

bool

at line 276
bool isError()

Determine whether the response represents an error.

Return Value

bool

at line 284
Role role()

Get the response role.

Return Value

Role