class ClientManager

Traits

Constants

protected CLIENTS_CONTEXT_KEY_PREFIX

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Client> $factories
protected Client> $clients

Keep the protected property while its clients belong to the current owner.

Methods

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.

void
registerClient(string $name, Closure $factory)

Register a named client factory.

client(string $name)

Get a named client for the current owner.

build(string $name)

Build a fresh named client from its factory or configuration.

fromConfig(string $name)

Build a client from its named configuration.

webClientFromConfig(string $key)

Build an HTTP client from its named configuration.

void
disconnectAll()

Disconnect every client owned by the current invocation.

void
disconnect(Client $client)

Disconnect a client while tolerating protocol teardown errors.

Details

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 53
void registerClient(string $name, Closure $factory)

Register a named client factory.

On the shared manager, factories persist across requests. Re-registration disconnects only the current owner's client; other owners retain theirs until cleanup.

Parameters

string $name
Closure $factory

Return Value

void

at line 68
Client client(string $name)

Get a named client for the current owner.

Parameters

string $name

Return Value

Client

at line 76
Client build(string $name)

Build a fresh named client from its factory or configuration.

Parameters

string $name

Return Value

Client

at line 90
protected Client fromConfig(string $name)

Build a client from its named configuration.

Parameters

string $name

Return Value

Client

at line 129
protected WebClient webClientFromConfig(string $key)

Build an HTTP client from its named configuration.

Parameters

string $key

Return Value

WebClient

at line 155
void disconnectAll()

Disconnect every client owned by the current invocation.

Return Value

void

at line 183
protected void disconnect(Client $client)

Disconnect a client while tolerating protocol teardown errors.

Parameters

Client $client

Return Value

void