Documentation

ApiClientRegistry
in package

FinalYes

Central registry for the HTTP clients used by API resource classes.

All resources share one lazily-created, middleware-configured default client. Individual classes can be given their own client without affecting the rest (test isolation, custom transports).

Table of Contents

Properties

$default  : HttpClientInterface|null
$overrides  : array<class-string, HttpClientInterface>

Methods

createConfiguredHttpClient()  : HttpClient
Create an HttpClient with middleware built from Config settings.
removeFor()  : void
Remove the override for one specific class.
reset()  : void
Clear the default client and all per-class overrides.
resolve()  : HttpClientInterface
Resolve the client for a class: its override if set, otherwise the shared default (created from Config middleware settings on first use).
setDefault()  : void
Set the shared default client used by every API class without an override.
setFor()  : void
Set a client for one specific class only.
createCacheMiddleware()  : CacheMiddleware
Build a CacheMiddleware from Config::setMiddleware()'s 'cache' entry.

Properties

Methods

removeFor()

Remove the override for one specific class.

public static removeFor(class-string $class) : void
Parameters
$class : class-string

The API class

reset()

Clear the default client and all per-class overrides.

public static reset() : void

Intended for test teardown so a mock set in one test never leaks into the next.

resolve()

Resolve the client for a class: its override if set, otherwise the shared default (created from Config middleware settings on first use).

public static resolve(class-string $class) : HttpClientInterface
Parameters
$class : class-string

The API class requesting a client

Return values
HttpClientInterface

createCacheMiddleware()

Build a CacheMiddleware from Config::setMiddleware()'s 'cache' entry.

private static createCacheMiddleware(array<string, mixed> $config) : CacheMiddleware

Accepts an 'adapter' as either an instance or a shorthand string ('memory', 'file', 'apcu'); 'cache_dir' applies to the file adapter. Configuring the cache implies enabling it unless 'enabled' is set explicitly.

Parameters
$config : array<string, mixed>

Cache middleware configuration

Return values
CacheMiddleware
On this page

Search results