Response
class Response
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
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.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a response with its content and role.
Create a notification response.
Create a response from a rendered view.
Create a structured response with a text representation.
Create a resource link response.
Create an image or audio response from a filesystem disk.
Create a response with the assistant role.
Determine whether the response is a notification.
Determine whether the response represents an error.
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.
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
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 34
protected
__construct(Content $content, Role $role = Role::User, bool $isError = false)
Create a response with its content and role.
at line 46
static Response
notification(string $method, array $params = [])
Create a notification response.
at line 54
static Response
text(string $text)
Create a text response.
at line 62
static Response
html(string $path)
Create a response from an HTML file.
at line 79
static Response
view(string $view, array $data = [], array $mergeData = [])
Create a response from a rendered view.
at line 91
static Response
json(mixed $content)
| internal |
Create a response containing JSON text.
at line 99
static Response
blob(string $content)
Create a binary response.
at line 109
static ResponseFactory
structured(array $response)
Create a structured response with a text representation.
at line 129
static Response
error(string $text)
Create an error response.
at line 137
Content
content()
Get the response content.
at line 147
static ResponseFactory
make(Response|array $responses)
Create a response factory.
at line 157
Response
withMeta(array|string $meta, mixed $value = null)
Add metadata to the response content.
at line 167
static Response
audio(string $data, string $mimeType = 'audio/wav')
Create an audio response.
at line 175
static Response
image(string $data, string $mimeType = 'image/png')
Create an image response.
at line 187
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.
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.
at line 260
Response
asAssistant()
Create a response with the assistant role.
at line 268
bool
isNotification()
Determine whether the response is a notification.
at line 276
bool
isError()
Determine whether the response represents an error.
at line 284
Role
role()
Get the response role.